WooCommerce Hide all shipping Methods if Total is less

Running a premium multi-national online store with orders coming from around the world often leaves you with no room for wasting time and effort.

A good way to boost and basically motivate the customers to buy from your store is to set a minimum price limit. This way neither time nor any efforts would go in vain.

WooCommerce allows you to make desirable changes to your website to maximize your sales. Below is a code which gives the functionality to hide all the shipping methods if the total amount of the customer’s cart is less than the minimum set amount.

Adding this functionality is a simple task and wouldn’t require more than a couple of minutes. You will just have to add the code below in the theme functions of your active child theme.

Go to Dashboard > Appearance > Theme Editor > Theme Functions

Then simply add the following code after the existing code,

[codesyntax lang=”php”]

add_filter( 'woocommerce_cart_needs_shipping', 'show_hide_shipping_methods' );

function show_hide_shipping_methods( $needs_shipping ) {
    $cart_items_total = WC()->cart->get_cart_contents_total();

    if ( $cart_items_total < 40 ) {
        $needs_shipping = false;
        // Optional: Enable shipping address form
         add_filter('woocommerce_cart_needs_shipping_address', '__return_true' );
    }

    return $needs_shipping;

}

[/codesyntax]

 

After pasting, click Update File. This code hides all shipping methods if the total is less than 40.

 

Before code:

After Code:

 

Waqas

I hope you enjoy reading this blog post. If you want my team to do WooCommerce Maintenance for you, click here.

Leave a Comment

Your email address will not be published. Required fields are marked *