Set a minimum order amount
Blocks checkout below the amount you set and shows a notice in the cart. Counts products with tax, before coupons and shipping.
add_action( 'woocommerce_check_cart_items', function() {
$min = 20;
$cart = WC()->cart;
if ( ! $cart || $cart->is_empty() ) {
return;
}
if ( (float) $cart->get_subtotal() + (float) $cart->get_subtotal_tax() < $min ) {
wc_add_notice(
sprintf( 'The minimum order amount is %s.', wc_price( $min ) ),
'error'
);
}
} );
These are the default values. Change them in the builder before you copy. Licensed under GPL-2.0-or-later, provided as is. Review and test it before using it on a live site.
How it works
WooCommerce runs woocommerce_check_cart_items every time it checks the cart, on the cart page and at checkout. The snippet adds up the products in the cart, with tax, and compares the total with your minimum. Below it, WooCommerce shows an error notice and doesn’t let the order through until more is added.
What counts toward the minimum
- Product prices, including tax.
- Coupons are not subtracted, so a discount doesn’t push a customer under the minimum.
- Shipping and fees don’t count.
The amount is in your store currency. Set it in the builder, under Minimum amount, before you copy the code.
How to check it works
Log out, add one cheap product and open the cart. You should see “The minimum order amount is …” and checkout should refuse the order. Add products past the minimum and the notice goes away.
How to undo it
Remove the code. The check stops on the next page load.
How to add this snippet
- Copy the code above.
- Paste it at the end of your child theme’s
functions.php, in Appearance → Theme File Editor or over FTP. - Save, then open the site and check that everything works. If something breaks, remove the code.
Need more than one? Open this snippet in the builder, turn on the others you want and copy them as one functions.php, or download them as a small plugin.