kekkodiaz
kekkodiaz

Reputation: 29

Remove one payment gateway if a coupon is applied

I'm trying to remove a specific payment gateway if at least 1 coupon is applied. I tried "Remove some payment gateways if any coupon code is applied in Woocommerce" answer code with no results, (the slug of the payment gateway to be removed is 'scalapay_gateway').

Any help?

Upvotes: 0

Views: 227

Answers (1)

Elman Huseynov
Elman Huseynov

Reputation: 1147

Try like this:

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(isset($available_gateways['scalapay_gateway'])){
          unset($available_gateways['scalapay_gateway']);
        }

    }

    return $available_gateways;
}

Upvotes: 1

Related Questions