Restricting payment types in ZenCart
Let’s say you sell two types of products in your cart. For example, BOOKS and eBOOKS.
You want to allow customers to pay for BOOKS with PayPal and credit cards. But you only want customers to pay for eBOOKS with PayPal.
Is this possible with ZenCart?
The answer is yes, however some editing of code is required.
First thing: Please make a backup of your files BEFORE editing them. This way, if you make a mistake, you can simply upload the original to restore order quickly.
Using Notepad or WordPad, open the payment file you wish to restrict. Using my example above, we want to restrict credit card payments, so we need to edit the cc.php file.
These files are located here:
yoursite/zencart/includes/modules/payment
Once opened, locate the following line of code:

*It only appears once in the file.
Directly after this code, add the following:
if (IS_ADMIN_FLAG == false) {
// disable if category 27 items are in the cart
if ($_SESSION['cart']->in_cart_check('master_categories_id','27') > 0) {
$this->enabled = false;
}
}
The file should now show like this:

IMPORTANT: Make sure you edit the category before saving and uploading. In my example above, I edited category 27. You need to replace BOTH instances with the category you wish to restrict payments for.
Alternatively, you can restrict payment by actual product instead of entire categories. To do this, you would use the following code instead of the code above:
if (IS_ADMIN_FLAG == false) {
// disable if products_id 27 is in the cart
if ($_SESSION['cart']->in_cart_check('products_id','27') > 0) {
$this->enabled = false;
}
}
Again, replacing the product number with your own.
Related tutorials that might interest you:
