Minimum Order Amount
Blocks checkout and shows a notice until the cart subtotal reaches a minimum amount (50 in your store currency by default).
Opens WPIDE on
Code
add_action( 'woocommerce_check_cart_items', function () {
$minimum = 50;
if ( ! function_exists( 'WC' ) || ! WC()->cart ) {
return;
}
$subtotal = (float) WC()->cart->get_subtotal();
if ( $subtotal > 0 && $subtotal < $minimum ) {
wc_add_notice(
sprintf( 'Your current subtotal is %1$s. The minimum order amount is %2$s.', wc_price( $subtotal ), wc_price( $minimum ) ),
'error'
);
}
} );
Notes
Works with the classic cart and checkout shortcodes. The subtotal is before tax and discounts.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.