WooCommerce
Set a WooCommerce minimum order value
Useful for: Wholesale, delivery and low-margin stores
Prevents checkout when the cart subtotal is below £25.
Change $minimum = 25; to the required amount.
/**
* Require a minimum WooCommerce order subtotal.
*/
function hmr_woocommerce_minimum_order_value(): void {
if ( ! function_exists( 'WC' ) || ! WC()->cart ) {
return;
}
$minimum = 25;
$subtotal = (float) WC()->cart->get_subtotal();
if ( $subtotal >= $minimum ) {
return;
}
$message = sprintf(
'A minimum order of %1$s is required. Your current subtotal is %2$s.',
wc_price( $minimum ),
wc_price( $subtotal )
);
if ( ! wc_has_notice( $message, 'error' ) ) {
wc_add_notice( $message, 'error' );
}
}
add_action(
'woocommerce_check_cart_items',
'hmr_woocommerce_minimum_order_value'
);
