MarketPress Batch import of coupon codes

I have a list of about 200 one time use coupon codes (from Groupon) that I want to add to my store. Has anyone does this before? I don't see any option to do a batch import and I certainly don't want to manually create each coupon. Is there a way I can export whichever table holds these codes as an.xls and then modify the .xls to include the new codes and import back in? If someone has any tips please share otherwise I'll work on it tonight and post a solution if I can get it to work.

  • Timothy
    • Chief Pigeon

    Hey there.

    Not sure I fully understand, so to confirm.

    Each Groupon will essentially be a product in your shop right?

    Or those codes will be actual discount coupons for use in your own shop?

    If they are products then can import CSV files:

    Admin --> Products --> Store Settings --> Importers

    Screen attached.


  • digitsoft
    • The Crimson Coder

    Solution for coupons...ugly BUT works.

    1. Edit /marketpress/marketpress.php
    2. Add these lines at line 5247:

    $mycoupons = array("COUPON1","COUPON2","COUPON3"); //NOTE - the coupon names MUST be upper case
    for ($k=0; $k<count($mycoupons); $k++)
    $coupons[$mycoupons[$k]]['discount'] = '10'; //how much of a discount
    $coupons[$mycoupons[$k]]['discount_type'] = 'pct'; //either amt (amount) or pct (percent)
    $coupons[$mycoupons[$k]]['start'] = strtotime('2012-01-01'); //start time in yyyy-mm-dd format
    update_option('mp_coupons', $coupons);

    3. Go to the coupons tab and click save - boom - 3 coupons!

    So line 5246 area should look like:

    $coupons[$new_coupon_code]['uses'] = (is_numeric($_POST['uses'])) ? (int)$_POST['uses'] : '';
    $mycoupons = array("COUPON1","COUPON2","COUPON3");
    for ($k=0; $k<count($mycoupons); $k++)
    $coupons[$mycoupons[$k]]['discount'] = '10';
    $coupons[$mycoupons[$k]]['discount_type'] = 'pct';
    $coupons[$mycoupons[$k]]['start'] = strtotime('2012-01-01');
    update_option('mp_coupons', $coupons);
              if (!$error) {

    Alright...the obvious thing is that unless each coupon has the same discount type and code this doesn't help, BUT you can add in your logic as you need.

    It was the best I could come up with on short notice....I may look at this further and will post updates.

  • digitsoft
    • The Crimson Coder

    Alright....a somewhat cleaner solution with csv import, but still hard coded.
    1. Add this after line 5246

    $handle = fopen("/home/myacct/public_html/test/wp-content/plugins/marketpress/test.csv", "r");
        while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
            $num = count($data);
            for ($c=0; $c < $num; $c++) {
    		switch ($c){
    			case 0:
    			case 1:
    				$coupons[$couponname]['discount'] = round($data[$c]);
    			case 2:
    				$coupons[$couponname]['discount_type'] = $data[$c];
    			case 3:
    				$coupons[$couponname]['start'] = strtotime($data[$c]);
    			case 4:
    				$coupons[$couponname]['end'] = strtotime($data[$c]);
    			case 5:
    				$coupons[$couponname]['uses'] = $data[$c];
    	update_option('mp_coupons', $coupons);

    2. Set the file handle on the first line to the full path on your server to where marketpress.php is located

    3. Create a csv file in this format (coupon name,amt or pct,start date,end date,how many max uses) no column name header:

    4. Put the csv file in the marketpress.php file folder

    5. Go to the Coupons tab and click Save - aside from the imported coupons you'll get 1 blank coupon that you can delete.

    6. // the code or just remove it after the CSV import

    I think this is the best option until a coupon code importer is implemented....

  • Michael B
    • Flash Drive

    I have gone through this a few times - adding the code as shown, etc - and have yet to see any effect. Marketpress has been updated since this was written so I'm wondering if it still applies in the same way? Can someone give a shout as to if this should still work as written. I have yet to get it to function. Thanks!

  • Michael B
    • Flash Drive

    How it went: it does not work.

    Sometimes I find this plugin that touts itself to be the best ecommerce plugin around (and costs money) to be really sort of lacking and rather disappointing.

    The suggestion I have received is in a post I made: if you want it to do that, then you should pay someone for it. Well, thanks guys!

  • Vaughan
    • Support/SLS MockingJay

    Hi @summer,

    It's a bit more complex than that. It stores the coupon data as a serialized array in the wp_options table

    Search for mp_options in the option_name column



    You will need to create a few different coupon types to see how the array changes, but editing it manually oyu'd need to understand serialized arrays.

    Hope this helps

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.