问题描述
感谢@Bhautik,如果购物车金额低于特定金额,我有不应用优惠券的解决方案.我的主题是:我有问题.我有优惠券可以给我 15% 的折扣.我也有最低 200 美元的运输方式.我注意到如果我在金额上应用优惠券 ~ 200 美元,小计低于 200 美元并且优惠券运输方式有效.如果小计低于 200 美元,我想创建一种方法来限制更智能的优惠券不被应用.我想取消单个优惠券代码的限制,成为任何人.
Thanks to @Bhautik I have solution to not apply coupon if cart amount goes below certain amount.My topic is:I have issue. I have coupon that give me 15% off. Also i have shipping method that works on minimum $200. I noticed if I apply coupon on amount ~ $200, subtotal goes under $200 and coupon shipping method worked. I am wondering to create a way to restrict smarter coupon to not be applied if subtotal goes below $200.I want to remove restriction from single coupon code and be anyone.
我们有解决方案
add_action( 'woocommerce_before_cart' , 'home_test_coupon_fix' );
add_action( 'woocommerce_before_checkout_form' , 'home_test_coupon_fix' );
function home_test_coupon_fix() {
global $woocommerce;
$cart_total = WC()->cart->get_subtotal();
$coupon_id = 'hometest';
$minimum_amount = 500 + WC()->cart->get_coupon_discount_amount( $coupon_id );
$currency_code = get_woocommerce_currency();
wc_clear_notices();
if ( $cart_total < $minimum_amount && $woocommerce->cart->applied_coupons[0] === $coupon_id ) {
WC()->cart->remove_coupon( 'hometest' );
wc_print_notice( "Get 50% off if you spend more than $minimum_amount $currency_code!", 'notice' );
}
wc_clear_notices();
}
推荐答案
删除此&&$woocommerce->cart->applied_coupons[0] === $coupon_id
适用所有优惠券的条件.试试下面的代码.
Remove this && $woocommerce->cart->applied_coupons[0] === $coupon_id
conditions for apply all coupons. Try the below code.
add_action( 'woocommerce_before_cart' , 'home_test_coupon_fix' );
add_action( 'woocommerce_before_checkout_form' , 'home_test_coupon_fix' );
function home_test_coupon_fix() {
global $woocommerce;
$cart_total = WC()->cart->get_subtotal();
$minimum_amount = 500 + WC()->cart->get_coupon_discount_amount( $woocommerce->cart->applied_coupons[0] );
$currency_code = get_woocommerce_currency();
wc_clear_notices();
if ( $cart_total < $minimum_amount ) {
WC()->cart->remove_coupon( $woocommerce->cart->applied_coupons[0] );
wc_print_notice( "Get 50% off if you spend more than $minimum_amount $currency_code!", 'notice' );
}
wc_clear_notices();
}
这篇关于如果金额低于特定金额,Woocommerce 不应用优惠券的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!