当我有"tcrfam“这样的特定优惠券时,我需要隐藏信用卡付款,当我使用与此不同的信用卡支付时,我的想法是我不给100%或免费的优惠券,也没有理由要求信用卡数据。
参见示例:

我试过这段代码,但不起作用:
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 cart需要付款‘,’__return_false‘);函数中的(如上面的代码所示),但我不知道如何做,有人能给我一个如何做它的想法吗?谢谢
发布于 2019-09-16 23:29:33
您需要的代码应该直接放在过滤器挂钩中,如下所示:
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文件中。应该行得通。
发布于 2020-12-21 14:36:40
我发现这个片段对我很有用,但我有个问题.如果禁用该方法的优惠券代码超过一个?我能用一下吗?
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 = '1code' || '2code';
if( in_array( $targeted_coupon_code, $cart->get_applied_coupons() ) ) {
$needs_payment = false;
}
return $needs_payment;
}我试过了,但是Woocommerce并没有问我每个优惠券代码的支付方法,而不仅仅是为了我写的2。
提前感谢
https://stackoverflow.com/questions/57963173
复制相似问题