1
votes

I am trying to restrict discounts or coupons if a customer selects a specific payment method. To do this, I have used a plugin called WooCommerce Extended Coupon Features.

I have 3 active payment methods: Cheque, Credit Card & PayPal in respective order. I set a coupon to restrict the discount being applied on the order if the payment method "PayPal" is selected.

However, at the Cart Page when I am adding a coupon to my order, I am getting the current error.

The coupon is not valid for the currently selected payment method.

I thought the default payment method for WooCommerce was to be the first one in sequential order yet it gives me that error. There are ways to programmatically un-apply the default payment method but I have not seen a method to apply it on the Cart page which is before the Checkout page.

I have tried the following:

  $available_gateways = $woocommerce->payment_gateways->get_available_payment_gateways();

  $available_gateways['cheque']->chosen = true;

But that only works for the Checkout page.

Any ideas?

1
It's not so clear… If I understand, your coupon is working only for Paypal payment method to restrict the all other discounts for Paypal. So If you force cheque as default, it's normal that you get that error, no? Then normally payment methods are selected on checkout page and not on cart page. So is kind of complicated. May be you will have to re-think it differently...LoicTheAztec
Sorry. I meant that I had the coupon set to be usable only on Cheque and credit card payment options and to un apply when PayPal is selected. On the cart page it seems no default payment option is selected. Hope this clears up things a bitDconsta
Yes that is perfectly clear now…thanksLoicTheAztec

1 Answers

0
votes

I had the same problem and I solved this way:

in woocommerce-auto-added-coupons/includes/WJECF_Controller.php look for this line:

//============================
    //Test restricted payment methods

and add this code before:

if (!isset( WC()->session->chosen_payment_method ) || WC()->session->chosen_payment_method == '' || !is_checkout()) {WC()->session->set('chosen_payment_method', 'paypal');}