How to set minimum order amount in WooCommerce

Here’s a handy WordPress code snippet which allows you to set minimum order amount in WooCommerce. If cart totals of a customer are below the minimum order amount, it display an error message and does not allow the customer to place order.

See Also: How to add custom field in WooCommerce checkout?

To set the minimum order amount, use the following code snippet.

//Set minimum order amount in WooCommerce
add_action( 'woocommerce_checkout_process', 'wc_minimum_order_amount' );
add_action( 'woocommerce_before_cart' , 'wc_minimum_order_amount' );
 
function wc_minimum_order_amount() {
	// Set this variable to specify a minimum order value
	$minimum = 50;

	if ( WC()->cart->total < $minimum ) {

		if( is_cart() ) {

			wc_print_notice( 
				sprintf( 'You must have an order with a minimum of %s to place your order, your current order total is %s.' , 
					woocommerce_price( $minimum ), 
					woocommerce_price( WC()->cart->total )
				), 'error' 
			);

		} else {

			wc_add_notice( 
				sprintf( 'You must have an order with a minimum of %s to place your order, your current order total is %s.' , 
					woocommerce_price( $minimum ), 
					woocommerce_price( WC()->cart->total )
				), 'error' 
			);

		}
	}

}

Source: http://docs.woothemes.com/document/minimum-order-amount/

4 Comments

  1. Great work Harshal!

    Now this snippet works for the whole cart.
    I wonder, is there a way to set a variable product to minimum quantity of 30 – making it possible to order 29 items of for example color blue and 1 item of color red? (Now, using different plugins like: Min Max Quantities For WooCommerce, VarkTech Minimum Purchase for WooCommerce, WooCommerce Advanced Product Quantities and Woocommerce Poor Guys Swiss Knife – they only let me choose 30 of the blue AND 30 of the red. They don’t start at 1, instead of 30). Do you know another plugin for this or another way to solve this?

    And have a set minimum quantity of 10 items on a single product? When on the product page the number of items I can put in the cart starts on 10, not 1.

    If I can’t solve this before you and you make everything work – I will open up the online course in juggling aimed to smarten school kids for free to you. Everything are in Swedish and for kids in 7-12 years of age.

    You would save my life!
    All the best
    /Pär

    Reply

Leave a Comment.