How to apply an automatic discount in WooCommerce based on cart total?

家住魔仙堡 提交于 2019-12-23 01:28:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!