如何为 woocommerce、paypal 和优惠券设置代码片段

问题描述

我需要设置使用优惠券激活付款方式的可能性。

例如“PayPal”只会在放置特定优惠券时显示。

我需要这个,因为我使用 PayPal 每月固定付款,没有利息。

如果使用优惠券,我有这个代码可以禁用贝宝,可能是相反的情况,但我还不能让它工作。

/*
add_filter('woocommerce_available_payment_gateways','bdev_unset_gatway_if_coupon');
function bdev_unset_gatway_if_coupon($available_gateways)
{

    $coupons = WC()->cart->applied_coupons;
    foreach ($coupons as $coupon) {

        if ($coupon) {

            // if the coupon name exist,remove BACS
            unset($available_gateways['paypal']);
        }

    }
    return $available_gateways;
}
*/

add_filter('woocommerce_available_payment_gateways','unset_gatway_by_applied_coupons');

function unset_gatway_by_applied_coupons($available_gateways)
{

    $coupons = WC()->cart->applied_coupons;

    foreach ($coupons as $coupon) {

        if ($coupon == 'enviodecen') { //here you can specific your coupon name
            unset($available_gateways['paypal']);
        }

    }

    return $available_gateways;
}

我非常感谢您的帮助

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...