Zen Cart Logo
Forums / Built-in Shipping and Payment Modules / Disable a payment method for a chosen shipping method?

Disable a payment method for a chosen shipping method?

Views: 2,790

Results 1 to 8 of 8
28 Oct 2014, 2:09 AM
#1
chowyungunz avatar

chowyungunz

New Zenner

Join Date:
Oct 2014
Posts:
20
Plugin Contributions:
0

Disable a payment method for a chosen shipping method?

For local pick up, I would like to restrict the payment method to just a cash payment. As of now on the payment page it shows the option to choose between my two installed payment modules, paypal standard or cash (COD). Is it possible to disable the paypal standard payment method for local pick up customers? Or vice versa, is it possible to disable the cash payment method (and show the paypal payment option only) for customers that choose shipping instead of local pick up? Any help would be greatly appreciated, thanks!

28 Oct 2014, 3:07 AM
#2
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Disable a payment method for a chosen shipping method?

Find the setting for the $this->enabled in the Payment module, such as, for example, PayPal Express:
/includes/modules/payment/paypalwpp.php

you would add the code in RED to disable the PayPal Express payment module when Store Pickup is selected ...

    $this->enabled = (MODULE_PAYMENT_PAYPALWPP_STATUS == 'True');
[B]    if (preg_match('#(storepickup)#i', $_SESSION['shipping']['id'])) {
      $this->enabled = false;
    }
[/B]

Note: PayPal Express is a much more reliable payment method than PayPal IPN ...

28 Oct 2014, 5:34 AM
#3
chowyungunz avatar

chowyungunz

New Zenner

Join Date:
Oct 2014
Posts:
20
Plugin Contributions:
0

Re: Disable a payment method for a chosen shipping method?

Ajeh:

Find the setting for the $this->enabled in the Payment module, such as, for example, PayPal Express:
/includes/modules/payment/paypalwpp.php

you would add the code in RED to disable the PayPal Express payment module when Store Pickup is selected ...

$this->enabled = (MODULE_PAYMENT_PAYPALWPP_STATUS == 'True');

[B] if (preg_match('#(storepickup)#i', $_SESSION['shipping']['id'])) {
$this->enabled = false;
}
[/B]

> 
> Note: PayPal Express is a much more reliable payment method than PayPal IPN ...

THANKS SO MUCH!!! That worked beautifully... took less time to implement than I spent searching for the answer!

On a side note, how is PayPal Express more reliable a payment method than PayPal Standard Payments?  Standard has worked well for me so far.  Maybe I should upgrade?
11 Jun 2015, 2:49 AM
#5
tronage avatar

tronage

New Zenner

Join Date:
May 2015
Posts:
32
Plugin Contributions:
0

Re: Disable a payment method for a chosen shipping method?

Ajeh:

Find the setting for the $this->enabled in the Payment module, such as, for example, PayPal Express:
/includes/modules/payment/paypalwpp.php

you would add the code in RED to disable the PayPal Express payment module when Store Pickup is selected ...

$this->enabled = (MODULE_PAYMENT_PAYPALWPP_STATUS == 'True');

[B] if (preg_match('#(storepickup)#i', $_SESSION['shipping']['id'])) {
$this->enabled = false;
}
[/B]

> 
> Note: PayPal Express is a much more reliable payment method than PayPal IPN ...

Please forgive me, I'm going to take a stab at reversing the logic for my needs...  I would like to hide cod for all the shipping options, and ONLY show it when a local pickup is chosen.
Would this be what I would do (I'm using 1.5.4 if that matters):
/includes/modules/payment/cod.php
$this->enabled = ((MODULE_PAYMENT_COD_STATUS == 'True') ? true : false);

[B] if (preg_match('#(storepickup)#i', $_SESSION['shipping']['id'])) {
$this->enabled = true;
}
[/B]

I "Think" I'm reversing the logic since I'm putting the code into the cod module, and hopefully only enabling it if the storepickup is chosen...  And I copied the $this statement from my current cod.php file (which looked a little different then the quoted one, I'm guessing changes for 1.5.4?).  In any case before I go hacking away and screwing something up, the question is if the above "should" work?
11 Jun 2015, 11:54 AM
#6
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,100
Plugin Contributions:
56

Re: Disable a payment method for a chosen shipping method?

tronage:

Please forgive me, I'm going to take a stab at reversing the logic for my needs... I would like to hide cod for all the shipping options, and ONLY show it when a local pickup is chosen.
Would this be what I would do (I'm using 1.5.4 if that matters):
/includes/modules/payment/cod.php

$this->enabled = ((MODULE_PAYMENT_COD_STATUS == 'True') ? true : false);

[B] if (preg_match('#(storepickup)#i', $_SESSION['shipping']['id'])) {
$this->enabled = true;
}
[/B]

> I "Think" I'm reversing the logic since I'm putting the code into the cod module, and hopefully only enabling it if the storepickup is chosen...  And I copied the $this statement from my current cod.php file (which looked a little different then the quoted one, I'm guessing changes for 1.5.4?).  In any case before I go hacking away and screwing something up, the question is if the above "should" work?
You probably want:
$this->enabled = ((MODULE_PAYMENT_COD_STATUS == 'True') ? true : false);

[B] if ($this->enabled) {
$this->enabled = (bool)preg_match('#(storepickup)#i', $_SESSION['shipping']['id']);
}
[/B]

That teeny change does two things:
1. It only enables the module if it's enabled in your admin
2. If enabled in the admin, it's only enabled if the shipping method chosen is "Store Pickup".  The value returned by preg_match is either 0 (no match), 1 (match) or false (error), so *casting *its return to a boolean value results in COD being enabled only if there is a match.
12 Jun 2015, 1:22 AM
#7
tronage avatar

tronage

New Zenner

Join Date:
May 2015
Posts:
32
Plugin Contributions:
0

Re: Disable a payment method for a chosen shipping method?

lat9:

You probably want:

$this->enabled = ((MODULE_PAYMENT_COD_STATUS == 'True') ? true : false);

[B] if ($this->enabled) {
$this->enabled = (bool)preg_match('#(storepickup)#i', $_SESSION['shipping']['id']);
}
[/B]

> That teeny change does two things:
> 1. >
2. It only enables the module if it's enabled in your admin
>
3. If enabled in the admin, it's only enabled if the shipping method chosen is "Store Pickup".  The value returned by preg_match is either 0 (no match), 1 (match) or false (error), so *casting *its return to a boolean value results in COD being enabled only if there is a match.
>
GENIOUS!:smartalec:
Popped in that code, and all works perfectly!  And like you said, if I decide to turn off COD in the admin, I don't have to go back and remove the code!
Thanks so much!!!
12 Jun 2015, 11:56 AM
#8
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,100
Plugin Contributions:
56

Re: Disable a payment method for a chosen shipping method?

Happy to have helped!