Quantcast
Channel: Themelocation
Viewing all articles
Browse latest Browse all 103

WooCommerce Hide all shipping Methods if Total is less

$
0
0

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,

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;
 
}

 

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

 

Before code:

After Code:

 


Viewing all articles
Browse latest Browse all 103

Trending Articles