问题
Referring to this question How do I programmatically apply a coupon in Woocommerce?
I'm looking for something very similar to the final solution in the first post, but I'd like the coupon to be applied if the subtotal is > 99 euros.
How do you think I can modify the code? And since I'm a newbie... where do I have to paste the whole code?
Thanks a lot
回答1:
Something like this could be done:
add_action('woocommerce_before_checkout_process','add_discount_at_checkout');
function add_discount_at_checkout(){
global $woocommerce;
$minorder = 99;
if( $woocommerce->cart->get_cart()->cart_contents_total>$minorder){
//APPLY COUPON HERE
}
}
So basically, if your cart total is greater than 99, you can do something, like add a coupon.
来源:https://stackoverflow.com/questions/17609128/how-to-apply-an-automatic-discount-in-woocommerce-based-on-cart-total