Reputation: 29
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
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