Blog

How to Make an Inactive Coupon Active in Zen Cart

Note: This article discusses a known bug in Zen Cart that is present in all versions up to and including version 1.3.9g.  Hopefully after reading this, the Zen Cart team will implement this simple fix.

Today a client was trying to re-enable one of his old coupon codes that had expired by simply changing the start and finish dates.  You’d be astonished to know this isn’t possible without deleting and recreating the coupon or by copying it and then using the copy.  Basically, extra steps that a store owner shouldn’t have to do.

So, I did a quick search of the Zen-Cart.com forum and found this thread from 2007 explaining the steps above.  http://www.zen-cart.com/forum/showthread.php?p=386571#post386571.  Wow, this thread is from 2007 and the bug still hasn’t been fixed?  So I looked into it and found it can be resolved with a single line of code. Took less time to fix than to perform the “recommended” rename/copy workaround.

Open admin/coupon_admin.php and find:

$sql_data_array = array('coupon_code' => zen_db_prepare_input($_POST['coupon_code']),
 'coupon_amount' => zen_db_prepare_input($_POST['coupon_amount']),
 'coupon_type' => zen_db_prepare_input($coupon_type),
 'uses_per_coupon' => zen_db_prepare_input((int)$_POST['coupon_uses_coupon']),
 'uses_per_user' => zen_db_prepare_input((int)$_POST['coupon_uses_user']),
 'coupon_minimum_order' => zen_db_prepare_input((float)$_POST['coupon_min_order']),
 'restrict_to_products' => zen_db_prepare_input($_POST['coupon_products']),
 'restrict_to_categories' => zen_db_prepare_input($_POST['coupon_categories']),
 'coupon_start_date' => $_POST['coupon_startdate'],
 'coupon_expire_date' => $_POST['coupon_finishdate'],
 'date_created' => 'now()',
 'date_modified' => 'now()',
 'coupon_zone_restriction' => $_POST['coupon_zone_restriction']);

Add after:

if ( (date('Y-m-d',time()) >= $_POST['coupon_startdate']) && ( (date('Y-m-d',time()) < $_POST['coupon_finishdate']) || !isset($_POST['coupon_finishdate']) ) $sql_data_array['coupon_active'] = 'Y';

I love Zen Cart, but seriously, something like this should have been fixed a lot sooner…

5 thoughts on “How to Make an Inactive Coupon Active in Zen Cart

  1. I have over 200 coupons showing in status “Active Coupon” that the expiration date has already passed on…. what is keeping these coupons from going to Inactive? Running 1.5.4


    1. That’s an unfortunate issue with how Zen Cart coded the coupon system. The expiration date seems to have no impact on the status column in the coupon table. We are working on our own plugin for better managing coupon codes and will definitely fix this issue in our plugin.



  2. Ahhh I see that apparently in v1.5.x this has been addressed.. (At least I was able to reactivate a coupon by simply changing the expiration date..) Delete my previous comment.. **lol**


  3. Found this little gem.. Thanks for it.. Can’t believe this STILL isn’t in the latest version of Zen Cart.. Anyway wanted to let you know that there is a slight “typo” in the code you posted here.. the “if” is missing the “i”..

    if ( (date('Y-m-d',time()) >= $_POST['coupon_startdate']) && (date('Y-m-d',time()) < $_POST['coupon_finishdate']) ) $sql_data_array['coupon_active'] = 'Y';


Leave a Reply

Your email address will not be published. Required fields are marked *

    Get quote Live
    Chat