Skip to content

Instantly share code, notes, and snippets.

@scottbuscemi
Created July 13, 2016 17:34
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 scottbuscemi/64211d3fd582ba2d55ef5c3977465c14 to your computer and use it in GitHub Desktop.
Save scottbuscemi/64211d3fd582ba2d55ef5c3977465c14 to your computer and use it in GitHub Desktop.
WooCommerce minimum order amount for subtotal only (don't include shipping+tax)
// Add to your functions.php file
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->subtotal < $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.' ,
wc_price( $minimum ),
wc_price( WC()->cart->subtotal )
), '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.' ,
wc_price( $minimum ),
wc_price( WC()->cart->subtotal )
), 'error'
);
}
}
}
@jmdonaldson
Copy link

This method seems to work. Rather than calling the two hooks:

add_action( 'woocommerce_checkout_process', 'wc_minimum_order_amount' );
add_action( 'woocommerce_before_cart' , 'wc_minimum_order_amount' );

Use this instead:
add_action( 'woocommerce_check_cart_items', 'wc_minimum_order_amount' );

It will stop you reaching the checkout unless purchase requirement is met

@asaphtunes
Copy link

Quick question:

How do i apply to this to international orders only. E.g. orders from America and canada I want to have it as minimum of 20 items need to be ordered. However for Australia have no minimum requirements?

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