I am using a snippet to set minimum order value on WooCommerce store. However, I am having some issues if coupon is applied.
For example, minimum order value is 500 and customer applies a coupon with a value of 500 – This would give a subtotal of 0 and therefore the system won’t allow the customer to buy because the subtotal is less than minimum order value.
I am therefore trying to rewrite the minimum order value snippet so it won’t set a minimum if a coupon is applied.
After doing some research I found that I should check if coupon is applied by using !empty($woocommerce->cart->applied_coupons)
. However, this doesn’t seem to work. What am I missing ??
// MINIMUM ORDER AMOUNT
add_action( 'woocommerce_checkout_process', 'wc_minimum_order_amount' );
add_action( 'woocommerce_before_cart' , 'wc_minimum_order_amount' );
function wc_minimum_order_amount() {
// Set this variable to specify a minimum order value
$minimum = 50;
if ( (WC()->cart->total <= $minimum) && !empty($woocommerce->cart->applied_coupons) ) {
if( is_cart() ) {
wc_print_notice(
sprintf( 'Your current order total is %s — you must have an order with a minimum of %s to place your order ' ,
wc_price( WC()->cart->total ),
wc_price( $minimum )
), 'error'
);
} else {
wc_add_notice(
sprintf( 'Your current order total is %s — you must have an order with a minimum of %s to place your order' ,
wc_price( WC()->cart->total ),
wc_price( $minimum )
), 'error'
);
}
}
}
2
Answers
You can calculate the order total amount is less than or equal to minimum amount, if it returns true means order total is 500 or less than 500, then you can show the error message.
Hope it works!
Maybe somthing like this?