mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-04-29 11:32:21 +08:00
30 lines
892 B
Text
30 lines
892 B
Text
add_action( 'woocommerce_check_cart_items', 'wc_minimum_order_amount' );
|
|
|
|
function wc_minimum_order_amount() {
|
|
// Set this variable to specify a minimum order value
|
|
$minimum = 50;
|
|
|
|
if ( WC()->cart->subtotal < $minimum ) {
|
|
|
|
if( is_cart() ) {
|
|
|
|
wc_print_notice(
|
|
sprintf( 'You must have an order with a minimum of %s to place your order, your current order total is %s.' ,
|
|
wc_price( $minimum ),
|
|
wc_price( WC()->cart->subtotal )
|
|
), 'error'
|
|
);
|
|
|
|
} else {
|
|
|
|
wc_add_notice(
|
|
sprintf( 'You must have an order with a minimum of %s to place your order, your current order total is %s.' ,
|
|
wc_price( $minimum ),
|
|
wc_price( WC()->cart->subtotal )
|
|
), 'error'
|
|
);
|
|
|
|
}
|
|
}
|
|
|
|
}
|