Zen Cart custom software development, Zen Cart modules, Zen Cart Expert eCommerce with Zen Cart!

Zen Cart Optional Payment Method

Zen Cart Optional Payment Method

A Zen Cart™ mod which allows you to make a specific payment module only visible to a subset of your customers.

Donate: This is free software. Show your appreciation by supporting my efforts. Donate

Relevance: Zen Cart™ 1.5.1 and above

Current Version: 1.3 (version history)

Support Thread: Optional Payment Method Support Thread

Cost: Free, but donation appreciated

Installed Cost: $100.00 Buy Professional Installation by That Software Guy

Installation Difficulty: Moderate

Installation Instructions: click here

Location: Zen Cart Plugins, under Admin Tools

Download: Optional Payment Method in Zen Cart Plugins


If you have a payment method that you want only certain customers to have access to, this module will help you do that.

It adds a checkbox (defaulted to unchecked) permitting the use of another payment module to the Admin > Customers > Customers screen.

Zen Cart Optional Payment in Edit Customer screen

Installation Instructions:

  1. Back up everything! Try this in a test environment prior to installing it on a live shop.
  2. Unzip the file you have received.
  3. In Admin > Tools > Install SQL Patches, run optional_payment.sql.
  4. In your copy of includes/classes/payment.php, in the first instance of the line
       $class = substr($value, 0, strrpos($value, '.')); 

    For Zen Cart 1.3.9 through 1.5.3, this is line 50
    In Zen Cart 1.5.4 this is line 51.
    In Zen Cart 1.5.7 this is line 52.
    Add the following logic below that line:
                  // bof optional payment method logic 
                  if ($class == 'braintree_api') {
                     global $db;
                     $cid = $_SESSION['customer_id'];
                     $class_ok = $db->Execute("SELECT optional_payment_1 FROM " . TABLE_CUSTOMERS . " WHERE customers_id = " . (int)$cid);
                     if ($class_ok->fields['optional_payment_1'] != 1) {
                  // eof optional payment method logic 
    Change braintree_api to the name of the payment module you want to be optional.
  5. Install admin/customers.php. Change the string "Allow use of BrainTree CC Module?" to one of your own choosing.
  6. If you want to allow customers to decide whether or not to show this payment module, just add the ability to get/set optional_payment_1 to the account_edit page and template.
  7. Donate! Show your appreciation by supporting my efforts.

Major Versions

  • 1.3 09/14/2021 - Updates for Zen Cart 1.5.7c
  • 1.2 01/02/2015 - Updates for Zen Cart 1.5.5a
  • 1.1 01/02/2015 - Updates for Zen Cart 1.5.4.
  • 1.0 12/01/2014 - First Release


Q: What are some ways I could further customize this mod?
A: Here's an example. With this change, the payment method will show up for customers with the optional payment method checkbox checked OR for purchases over a certain amount.

Here’s the code to add to the payment method of the payment class.  Right above where the mod has you add

 // bof optional payment module logic

change this to

 $payment_threshold = 400;
 global $order; 
 // Enable if total > threshold.
 if ($class_ok->fields['optional_payment_1'] != 1) {
    if ($order->info['total'] >= $payment_threshold) {
       $class_ok->fields['optional_payment_1'] = 1;
 // bof optional payment module logic

This turns it on for all transactions over $400. To turn it on for all transactions over $400 AND where the customer has been configured to use the payment method, do this instead:

 $payment_threshold = 400;
 global $order; 
 // Enable if total > threshold AND customer enabled
 if ($class_ok->fields['optional_payment_1'] == 1) {
    $class_ok->fields['optional_payment_1'] = 0;
    if ($order->info['total'] >= $payment_threshold) {
       $class_ok->fields['optional_payment_1'] = 1;
 // bof optional payment module logic

Q: Could I use this in the Invoice Payment Method mod to determine eligibility, rather than using the customer's group id?
A: Yes! That's exactly the idea.