This snippet prevents customers from checking out unless their cart meets a minimum order value. It’s useful for covering shipping costs on small orders or as one layer of protection against card testing fraud, where attackers test stolen cards with small transactions.
Add this snippet using a code snippets plugin (recommended) or your theme’s functions.php file:
/**
* Set minimum order amount for WooCommerce
*
* @link https://kestrelwp.com/docs/woocommerce-minimum-order-amount/
*/
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'
);
}
}
Change the $minimum value to whatever makes sense for your store.
When a customer tries to checkout with a cart total below your minimum, they’ll see an error message and won’t be able to complete the order.