Page 1 of 1

Hide payment method if specific shipping method selected

Posted: Wed Oct 19, 2016 6:36 pm
by bartek2334
Hi Everyone

I want to hide specific payment method (cash on delivery) if specific shipping method selected before. For example, if I check shipping method A , then in the next step, payment methods I have only one method to check ( other methods disabled or unable to check). I try to edit and add some code to payment_method.php and shipping_method.php file in controller/checkout directory, but so far I havent' find the solution.

I tried to get shipping method name/code and build a conditional statement in payments, but I don't know exactly how to deal with it.

Any other ideas how to solve this issue ?

Best

Bartosz

Re: Hide payment method if specific shipping method selected

Posted: Wed Oct 19, 2016 10:31 pm
by Johnathan
Restrict Payment Methods can do this. You'd set it up like this:

------------------------------------------------------------------------------
RESTRICTION #1
Name: Enable COD if not Shipping Method A
Payment Methods: COD
Rule: Shipping Method is not Shipping Method A
------------------------------------------------------------------------------

Feel free to take a look at the screenshots and demo site, and if you're interested let me know at www.getclearthinking.com/contact if you have any further questions.

Re: Hide payment method if specific shipping method selected

Posted: Mon Dec 19, 2016 6:14 pm
by openmandrake
Inside the checkout process shipping method is selected and stored inside the session.

The respective code is found here:
https://github.com/opencart/opencart/bl ... d.php#L125

Inside the model of the respective payment method you could add the if statement. If the model don't return the $method_data, the payment method is not available for checkout. E.g.
https://github.com/opencart/opencart/bl ... cod.php#L8

Something like this needs to be done:

Code: Select all

if (isset($this->session->data['shipping_method']) && $this->session->data['shipping_method'] == 'something_you_want_to_disallow') {
   $status = false;
}

Re: Hide payment method if specific shipping method selected

Posted: Thu Sep 05, 2019 3:43 am
by stijnman
Check out Shipping based payments OpenCart 2.3/3.0 (FREE MODULE)
https://www.opencart.com/index.php?rout ... n_id=31726

you can set for each shipping method all the specific payment methods