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

How to Set Minimum Order Amount ($) Based on Shipping Zone in WooCommerce (and also restrict order placement)?

With this custom code, you can enforce a minimum order amount based on the customer’s shipping zone before allowing them to proceed to checkout in WooCommerce. If the minimum order amount of the specified shipping zone is not met, an error notice message is displayed to the customer.

add_action( 'woocommerce_check_cart_items', 'ts_min_num_products' );

// Only run in the Cart or Checkout pages
function ts_min_num_products() {
	
	if( is_cart() || is_checkout() ) {
		global $woocommerce;

		// Set the minimum order amount and shipping zone before checking out
        $minimum = 200;
	  	$county 	= array('IN');
		
		// Defining var total amount      
        $cart_tot_order = WC()->cart->total;
        
	  	// Compare values and add an error in Cart's total amount
	    // happens to be less than the minimum required before checking out.
		// Will display a message along the lines 
     
		if( $cart_tot_order < $minimum && in_array( WC()->customer->get_shipping_country(), $county )  ) {
			// Display error message
	        wc_add_notice( sprintf( '<strong>A Minimum order of $%s is required before checking out.</strong>' 
	        	. '<br />Current order: $%s.',
	        	$minimum,
                $cart_tot_order	),
	        'error' );
		}
	}
}

Output

The output shows that when the customer attempts to proceed to checkout with an order total below the defined minimum and falls within the specified shipping zone, an error notice is triggered.

How to Set Minimum Order Amount ($) Based on Shipping Zone in WooCommerce (and also restrict order placement)? - Tyche Softwares

Also, you can just display the remaining cost for customer to avail free shipping on your WooCommerce cart irrespective of any shipping zone the notice message gets displayed.

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

Share It:

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