This snippet stops customers from checking out until their cart reaches a minimum value. It’s useful for covering shipping costs on small orders, or as one layer of protection against card testing fraud, where attackers try stolen cards with small transactions.
When you’d use this
- Small orders cost you more to ship than they earn.
- You’ve seen card testing attempts and want small carts to be turned away.
How to use it
1. Add the snippet
Add this snippet with a code snippets plugin (recommended) or your theme’s functions.php file:
/**
* Set minimum order amount for WooCommerce
*
* @link https://kestrelwp.com/docs/minimum-order-amount-in-woocommerce/
*/
add_action( 'woocommerce_check_cart_items', 'kestrel_minimum_order_amount' );
function kestrel_minimum_order_amount() {
$minimum = 5; // Minimum order amount in your store's currency
if ( WC()->cart->get_subtotal() < $minimum ) {
wc_add_notice(
sprintf(
'Your order must be at least %s to checkout.',
wc_price( $minimum )
),
'error'
);
}
}
2. Set your minimum
Change $minimum to the amount that makes sense for your store. The check uses the cart subtotal before coupons, shipping and tax.
3. Test it
Add a product worth less than your minimum to the cart and go to checkout. You’ll see "Your order must be at least" followed by your minimum, and the order can’t be placed. This works on both the classic checkout and the checkout block.
