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

Coupon Extensions for Zen Cart

This page describes the various modifications I offer for Zen Cart's coupon system:

Using Coupons with My Discount Modifications

You may indicate that a coupon is required to get a specific discount in Big Spender, Big Chooser, Discount Spender or Discount Chooser. This can be advantageous for several reasons:
  • You want to limit the number of times a discount can be taken, which can be done using the Uses Per Customer field of coupons (see Admin > Gift Certificate/Coupons > Coupon Admin > Edit)
  • You want to track how many times a specific discount is taken, which can be done using coupons
  • You want to limit a discount to only certain customers (who have been informed of the coupon code through a specific advertisement or promotion).

Using Coupons with Discount Spender and Discount Chooser

Discount Spender and Discount Chooser both have a section in the GUI where coupon codes may be entered.

Using Coupons with Big Spender, Big Chooser and Coupon Auto Add

Big Spender and Big Chooser both have a "set_coupon" parameter (see here and here). The only downside is that the human interface is a bit odd, for a specific reason: in order to make the Zen Cart coupon system work, you must give the coupon a dollar amount or make it a free shipping coupon. You cannot simply create a $0.00 coupon and use this as your coupon in the set_coupon parameter. Since free shipping is sometimes not feasible, this means you will see your discount, plus a one penny additional discount.

Payment Page displaying Big Chooser Discount based on coupon

Zen Cart Payment page showing Big Chooser Discount based on coupon

Creating Zero Dollar Coupons

Some storeowners wish to create Big Spender or Big Chooser discounts which require a coupon code (for exclusivity, to track an advertisement's performance or for some other reason). Since the discount is applied by Big Spender or Big Chooser, they don't want the coupon to have additional value. You can make a coupon with value $0.01 and have no problem, but if you want a coupon worth less than a penny, you must use a trick and make some code changes.

The trick is to assign the coupon a value of $0.001 (one tenth of a penny). Such coupons will not reduce the order total, but - when used in conjunction with the changes shown below - can be tracked throughout the Zen Cart order flow.

If you use coupons with a value of $0.001 with Discount Chooser or Discount Spender, Big Chooser or Big Spender, you need to make a tweak to the ot_coupon.php file.

The reasoning behind a coupon with a value of $0.001 is that it will show up as $0.00 in the checkout page but will still record correctly in the coupon tracking table.

Zero Dollar Coupons in Zen Cart 1.5.6

You can make $0.001 coupons work in 1.5.6 by making the following changes in includes/modules/order_total/ot_coupon.php
Change line 553 from:
              $od_amount['total'] = zen_round(($coupon->fields['coupon_amount'] > $orderTotalDetails['orderTotal'] ? $orderTotalDetails['orderTotal'] : $coupon->fields['coupon_amount']) * ($orderTotalDetails['orderTotal']>0), $currencyDecimalPlaces);

to
              $rounding_level = $currencyDecimalPlaces; 
              if ($coupon->fields['coupon_amount'] < 0.01) {
                 $rounding_level = 3;
              }
              $od_amount['total'] = zen_round(($coupon->fields['coupon_amount'] > $orderTotalDetails['orderTotal'] ? $orderTotalDetails['orderTotal'] : $coupon->fields['coupon_amount']) * ($orderTotalDetails['orderTotal']>0), $rounding_level);


Then change line 472 from:
    if ($this->deduction !=0) {

to
    if ($this->deduction > 0) {

Zero Dollar Coupons in Zen Cart 1.5.5

You can make $0.001 coupons work in 1.5.5 by making the following changes in includes/modules/order_total/ot_coupon.php
In 155a-c, change line 430 / In 155d-f, change line 432 from:
              $od_amount['total'] = zen_round(($coupon->fields['coupon_amount'] > $orderTotalDetails['orderTotal'] ? $orderTotalDetails['orderTotal'] : $coupon->fields['coupon_amount']) * ($orderTotalDetails['orderTotal']>0), $currencyDecimalPlaces);

to
              $rounding_level = $currencyDecimalPlaces; 
              if ($coupon->fields['coupon_amount'] < 0.01) {
                 $rounding_level = 3;
              }
              $od_amount['total'] = zen_round(($coupon->fields['coupon_amount'] > $orderTotalDetails['orderTotal'] ? $orderTotalDetails['orderTotal'] : $coupon->fields['coupon_amount']) * ($orderTotalDetails['orderTotal']>0), $rounding_level);


Then in 1.5.5a-c, change line 380 / in 1.5.5d-f, change line 381 from:
    if ($this->deduction !=0) {

to
    if ($this->deduction > 0) {

Zero Dollar Coupons in Zen Cart 1.5.4

You can make $0.001 coupons work in 1.5.4 by making the following changes in includes/modules/order_total/ot_coupon.php
Change line 431 from:
              $od_amount['total'] = zen_round(($coupon->fields['coupon_amount'] > $orderTotalDetails['orderTotal'] ? $orderTotalDetails['orderTotal'] : $coupon->fields['coupon_amount']) * ($orderTotalDetails['orderTotal']>0), $currencyDecimalPlaces);

to
              $rounding_level = $currencyDecimalPlaces; 
              if ($coupon->fields['coupon_amount'] < 0.01) {
                 $rounding_level = 3;
              }
              $od_amount['total'] = zen_round(($coupon->fields['coupon_amount'] > $orderTotalDetails['orderTotal'] ? $orderTotalDetails['orderTotal'] : $coupon->fields['coupon_amount']) * ($orderTotalDetails['orderTotal']>0), $rounding_level);


Then change line 381 from:
    if ($this->deduction !=0) {

to
    if ($this->deduction > 0) {

Zero Dollar Coupons in Zen Cart 1.5.2/1.5.3

Make the same change recommended for 1.5.0/1.5.1 on line 432 of includes/modules/order_total/ot_coupon.php

Then change line 382 from:
    if ($this->deduction !=0) {

to
    if ($this->deduction > 0) {

Zero Dollar Coupons in Zen Cart 1.5.0/1.5.1

You can make $0.001 coupons work in 1.5.0 and 1.5.1 by making a one line change in includes/modules/order_total/ot_coupon.php
Change line 419 from:
$od_amount['total'] = zen_round($coupon->fields['coupon_amount'] * ($orderTotalDetails['orderTotal']>0), $currencyDecimalPlaces);

to
$od_amount['total'] = zen_round($coupon->fields['coupon_amount'] * ($orderTotalDetails['orderTotal']>0), 3);


Zero Dollar Coupons in Zen Cart 1.3.9

You can make $0.001 coupons work in 1.3.9 by making a one line change in includes/modules/order_total/ot_coupon.php
Change line 399 from:
$od_amount['total'] = round($coupon->fields['coupon_amount'] * ($orderTotal>0), 2);

to
$od_amount['total'] = round($coupon->fields['coupon_amount'] * ($orderTotal>0), 3);

Older versions such as 1.3.8 and 1.3.7 did not require a change (but you should not be using these versions anymore).

Payment Page displaying Big Chooser Discount based on Zero Dollar Coupon

Zen Cart Payment page showing Big Chooser Discount based on Zero Dollar coupon

Note that the Tax must be the last item before the Total, for stores which charge tax. Adjust the sort order for the Tax module in Admin > Modules > Order Total> Tax.

Using Auto Coupons with Big Spender and Big Chooser

If you are using an automatic coupon generating program such as Spender AutoCoupon or Chooser AutoCoupon, you can make a coupon generated by this system a dependency for a Big Spender or Big Chooser discount. This is what the set_auto_coupon() parameter does. For instance, suppose you want to create a 20% off coupon good for 30 days automatically for people who spend $100 or more. Using Spender Autocoupon, you would put the following in your includes/modules/spender_autocoupon.php file:
         $this->add_threshold(100, 'Spend over $100 get a 20% off coupon', 'TEMPLATE_SAVETWENTY', 'SAVETWENTY_100', 30, 'D', 1);
where TEMPLATE_SAVETWENTY is a 20% off coupon. But suppose you want this to have more impact: for instance, an additional 25% of items from category 3. Create the following Big Chooser discount (i.e. edit includes/modules/order_total/ot_big_chooser.php and add this to the setup function):
         $this->add_condition('25% off category 3', true);
         $this->set_discount(CAT, 3, '*', "%", 25);
         $this->set_auto_coupon("SAVETWENTY_100");
Note that SAVETWENTY_100 is the new coupon name from the add_threshold command from Spender AutoCoupon.

Payment Page displaying Big Chooser Discount and AutoCoupon discount

Zen Cart Payment page showing Big Chooser Discount and AutoCoupon discount

Finally, you can create an AutoCoupon which is specifically designed for use with Big Chooser or Big Spender. For instance, suppose you wanted to have a special where with a purchase of $100 or more, you would create a 6 month coupon good for a free item from category 3 (shoes). Create a coupon for $0.01 called TEMPLATE_SHOES. Using Spender Autocoupon, you would put the following in your includes/modules/spender_autocoupon.php file:
         $this->add_threshold(100, 'Spend over $100 get a coupon for a pair of free shoes', 'TEMPLATE_SHOES', 'SHOES', 6, 'M');


Then create the following Big Chooser discount (i.e. edit includes/modules/order_total/ot_big_chooser.php and add this to the setup function):
         $this->add_condition('1 Pair free shoes (category 3)', false);
         $this->set_discount(CAT, 3, 1, "%", 100);
         $this->set_auto_coupon("SHOES");


Customers who checkout will now get a coupon with the code AUTO_xxx_yyy (where xxx is their customer id, and yyy is the entry number in the autocoupon table). When they redeem this coupon - which only they can use - they will see the following at checkout:

As another example of an AutoCoupon which is specifically designed for use with Big Chooser, consider the following example. Suppose you wanted to have a special where with a purchase of $100 or more, you would create a 3 month coupon good for a free item from MANUFACTURER 7 (Sony). Create a coupon for $0.01 called TEMPLATE_SONY. Using Spender Autocoupon, you would put the following in your includes/modules/spender_autocoupon.php file:
         $this->add_threshold(100, 'Spend over $100 get a coupon for free item from Sony', 'TEMPLATE_SONY', 'SONY', 3, 'M');


Then create the following Big Chooser discount (i.e. edit includes/modules/order_total/ot_big_chooser.php and add this to the setup function):
         $this->add_condition('1 free Sony item (MANUF 7)', false);
         $this->set_discount(MANUF, 7, 1, "%", 100);
         $this->set_auto_coupon("SONY");


This works the same way as the previous example.

Restricting the use of Coupons

Zen Cart already has a mechanism to restrict coupons to certain specific items. But what if you want more complex conditions - for example, two specific items (A and B) must be in the cart? The coupon is only applicable to a certain group? Coupon Restrictions - Big Chooser Style allows you to add Zen Cart Big Chooser style restrictions to specific coupons. Take a look at the examples for some ideas of how you can use it to create more targeted coupons for your business.

Note: Coupon Restrictions - Big Chooser Style only determines the coupon may be used or not - it doesn't change the discount calculation. A common request is "please change coupons to only apply to items not on sale or special." If you want that change, please see my Zen Cart Coupons No Sale or Special mod.

Coupon Single User allows you to restrict a coupon to one user.

Note: Like Coupon Restrictions - Big Chooser Style, Coupon Single User only determines whether or not the coupon may be used - it doesn't change the discount calculation.

Coupons don't know about Big Spender and Big Chooser

Remember that Coupons and Big Chooser don't know about each other; if you create a Big Chooser discount on Manufacturer Sony and make it dependent upon coupon Sony (as above), people can still enter the coupon code "SONY", and the coupon system will accept it. If they check out in this state, the coupon will be marked as used.

Of course, this same caveat applies to Coupons and Big Spender.

Digital Product Upgrade

Digital Product Upgrade allows you to sell updated versions of your digital products to prior purchasers for a fixed, discounted price.