0

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?

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
kekkodiaz
  • 29
  • 5

1 Answers1

1

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;
}
Elman Huseynov
  • 1,127
  • 1
  • 8
  • 18