Skip to content

Instantly share code, notes, and snippets.

@ChromeOrange
Created February 3, 2015 11:41
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChromeOrange/33af495f6afdd5d7a397 to your computer and use it in GitHub Desktop.
Save ChromeOrange/33af495f6afdd5d7a397 to your computer and use it in GitHub Desktop.
Set a minimum order amount in WooCommerce and disable checkout page if it is not met
add_action( 'woocommerce_check_cart_items', '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 ) {
WC()->add_error( 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 )
) );
}
}
@huykon
Copy link

huykon commented Feb 13, 2017

how to I can get value minimum amout of free shipping method in checkout page ?

@pattikawa
Copy link

how can I set minimum order amount depending on country?

@pattikawa
Copy link

add_action( 'woocommerce_check_cart_items', 'wc_minimum_order_amount' );

function wc_minimum_order_amount() {
// Set this variable to specify a minimum order value for a specific country
$minimum = 50;
$county = array('US');

if ( WC()->cart->total < $minimum && in_array( WC()->customer->get_shipping_country(), $county ) {
	  
	  WC()->add_error( 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 )
			) );

}

}

@pattikawa
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment