禁用“购物车需要付款"功能在Woocommerce中获取特定的优惠券代码 [英] Disable "cart needs payment" for a specific coupon code in Woocommerce
问题描述
当我有特定的优惠券(例如"tcrfam")时,我需要隐藏信用卡付款,并且当我使用任何其他与此优惠券显示的付款方式时,我的想法是我不会提供100%的优惠券还是免费的,在任何情况下我都不会询问信用卡数据.
I need to hide the payment by credit card when I have a specific coupon such as "tcrfam" and when I use any different to this show the payment by card, the idea is that I do not give a coupon of 100% or free and there is no case I ask credit card data.
请参见示例:
我尝试了此代码,但不起作用:
I tried this code but dont work:
add_action('woocommerce_before_checkout_form', 'apply_product_on_coupon');
function apply_product_on_coupon() {
global $woocommerce;
$coupon_id = 'tcrfam';
if(in_array($coupon_id, $woocommerce->cart->get_applied_coupons())){
echo "Yes the coupon its inserted dd";
add_filter( 'woocommerce_cart_needs_payment', '__return_false' );
}
}
我需要在上面的代码中使用 add_filter("woocommerce购物车需要付款",'__ return_false'); ,但我不知道该怎么做,有人可以给吗给我一个怎么做的想法?谢谢
I need to use add_filter ('woocommerce cart needs payment', '__return_false'); within the function as in the code above but I don't know how to do it, can someone give me an idea of how to do it? Thank you
推荐答案
您需要的代码应直接位于过滤器挂钩中,例如:
The code that you needs should be in the filter hook directly, like:
add_filter( 'woocommerce_cart_needs_payment', 'filter_cart_needs_payment', 10, 2 );
function filter_cart_needs_payment( $needs_payment, $cart ) {
// The targeted coupon code
$targeted_coupon_code = 'tcrfam';
if( in_array( $targeted_coupon_code, $cart->get_applied_coupons() ) ) {
$needs_payment = false;
}
return $needs_payment;
}
代码进入您的活动子主题(或活动主题)的functions.php文件中.应该可以.
Code goes in functions.php file of your active child theme (or active theme). It should works.
这篇关于禁用“购物车需要付款"功能在Woocommerce中获取特定的优惠券代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!