Skip to content
Advertisement

Remove some payment gateways if any coupon code is applied in Woocommerce

I started to work on small Woocommerce project. I have 3 payment gateways into this store: Paypal, Credit Card and Direct bank Transfer.

What I would like is: If coupon code is used, I would like to disable (or remove) Paypal and Credit Card from available payment gateways, and just keep “Direct bank Transfer” as available payment gateway choice.

To show how is look current state from checkout page:

image

I found a similar solution, but this is for removing gateway based on product category.

JavaScript

So I think that this function can be used, but slightly modified per my problem.

Any help is appreciated.

Advertisement

Answer

The following code will remove all payment gateways except “Direct bank Transfer” (bacs) only if at least one coupon code has been applied by the customer:

JavaScript

Code goes in function.php file of the active child theme (or active theme). Tested and works.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement