Zen Cart Logo
Forums / General Questions / Restricting payment methods to only certain categories

Restricting payment methods to only certain categories

Views: 1,067

Results 1 to 7 of 7
7 Dec 2011, 3:02 PM
#1
delia avatar

delia

Totally Zenned

Join Date:
May 2006
Location:
Gardiner, Maine
Posts:
2,383
Plugin Contributions:
7

Restricting payment methods to only certain categories

I've had 2 clients request the ability to limit payment methods to only certain categories. For example, one has products that he is not allowed to take payments from paypal but can accept payments thru authorize.net for the same productsl. These products are in one category only.

I would assume that you could add in a switch to the specific payment method itself not to allow for certain categories (haven't considered that thru yet so I could be wrong) but would it be possible to add this as a switch for all payment methods rather than do one at a time?

7 Dec 2011, 3:41 PM
#2
ajeh avatar

ajeh

Oba-san

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

Re: Restricting payment methods to only certain categories

If you wanted to disable PayPal Express for Products in categories_id 12, where categories_id 12 is the master_categories_id for these Products ... then you can customize the code in RED:
/includes/modules/payment/paypalwpp.php

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

// bof: do not show for categories_id 12 based on master_categories_id
    if (!IS_ADMIN_FLAG) {
      global $cart;
      $chk_cat = $_SESSION['cart']->in_cart_check('master_categories_id','12');
      if ($chk_cat > 0) {
        $this->enabled = false;
      }
    }
// eof: do not show for categories_id 12 based on master_categories_id
15 Dec 2011, 5:05 PM
#3
delia avatar

delia

Totally Zenned

Join Date:
May 2006
Location:
Gardiner, Maine
Posts:
2,383
Plugin Contributions:
7

Re: Restricting payment methods to only certain categories

wow, you must have answered during my server changes. Just saw this - now got to remember who was asking for it!

Thanks once again!

15 Dec 2011, 5:06 PM
#4
ajeh avatar

ajeh

Oba-san

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

Re: Restricting payment methods to only certain categories

You are most welcome ... :smile:

30 Dec 2014, 5:31 PM
#5
shopville avatar

shopville

Zen Follower

Join Date:
Aug 2012
Posts:
331
Plugin Contributions:
0

Re: Restricting payment methods to only certain categories

Ajeh:

If you wanted to disable PayPal Express for Products in categories_id 12, where categories_id 12 is the master_categories_id for these Products ... then you can customize the code in RED:
/includes/modules/payment/paypalwpp.php

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

// bof: do not show for categories_id 12 based on master_categories_id
if (!IS_ADMIN_FLAG) {
global $cart;
$chk_cat = $_SESSION['cart']->in_cart_check('master_categories_id','12');
if ($chk_cat > 0) {
$this->enabled = false;
}
}
// eof: do not show for categories_id 12 based on master_categories_id


Hi,
Can i add restrictions for product ID s as well (in addition to blocking categories) 
TIA
30 Dec 2014, 5:37 PM
#6
ajeh avatar

ajeh

Oba-san

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

Re: Restricting payment methods to only certain categories

Let's say you want to add products_id 33 and another categories_id 45 just to show you how those would work:
$this->enabled = (MODULE_PAYMENT_PAYPALWPP_STATUS == 'True');

[B]// bof: do not show for categories_id 12 and 45 based on master_categories_id and products_id 33
    if (!IS_ADMIN_FLAG) {
      global $cart;
      $chk_cat = $_SESSION['cart']->in_cart_check('master_categories_id','12');
      $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','45');
      $chk_cat += $_SESSION['cart']->in_cart_check('products_id','33');
      if ($chk_cat > 0) {
        $this->enabled = false;
      }
    }
// eof: do not show for categories_id 12 and 45 based on master_categories_id and products_id 33
[/B]

the += keeps adding on to the count for $chk_cat for each categories_id where master_categories_id matches and for specific products_id where the products_id matches ...

The $_SESSION['cart']->in_cart_check can check cart content based on many things, and only on occasion is there any reason to touch the actual shopping_cart.php class file to obtain matches for various types of checks regarding what is in the shopping_cart ...

30 Dec 2014, 5:53 PM
#7
shopville avatar

shopville

Zen Follower

Join Date:
Aug 2012
Posts:
331
Plugin Contributions:
0

Re: Restricting payment methods to only certain categories

Thanks so much!