Black Friday & Cyber Monday SUPER SALE ALL WEEK:
Grab 40% OFF on plugins
Days
Hours
Minutes
Seconds

How to Set Default Shipping Method in WooCommerce Cart?

If you want to set “Local pickup” as the default shipping method on the cart and checkout page, use the below snippet.

add_action( 'woocommerce_before_cart', 'ts_default_shipping_method', 5 );
function ts_default_shipping_method(){

    if( count( WC()->session->get('shipping_for_package_0')['rates'] ) > 0 ){
        foreach( WC()->session->get('shipping_for_package_0')['rates'] as $rate_id =>$rate)
            if($rate->method_id == 'local_pickup'){
                $default_rate_id = array( $rate_id );
                break;
            }
        WC()->session->set('chosen_shipping_methods', $default_rate_id );
    }
}

Output

When a customer adds an item to their cart and clicks on “View Cart,” they are redirected to the cart page where the default shipping method is set to “Local Pickup” as shown below.

How to Set Default Shipping Method in WooCommerce Cart? - Tyche Softwares

Instead of making any shipping method as the default one, you can also hide the shipping method which you don’t require. This post will help you to hide WooCommerce shipping methods for certain conditions based on cart total, product weight, product quantity, etc.

Browse more in: Code Snippets, WooCommerce How Tos, WooCommerce Tutorials

Share It:

Subscribe
Notify of
0 Comments
Newest
Oldest
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x