skip to Main Content

I’m installing some tracking code into the checkout_success.php page. I need to be able to grab the coupon code/discount code name from the order, if one was used so that I can echo it out in my tracking script.

I was wondering if anyone knows how to do this?

I’m using this contribution of discount coupons; ot_discount_coupons.php, August 4, 2006, author: Kristen G. Thorson, ot_discount_coupon_codes version 3.0

It seems that the coupon code is not actually stored in the order_totals, but in a seperate discount_coupons_to_orders table. is there a query i can do on this table to find the matching coupon code used for this order? i tried the following but it return nothing;

$coupon_query = tep_db_query("select coupons_id from discount_coupons_to_orders where orders_id = '".(int)$orders['orders_id']."' ORDER BY orders_id DESC LIMIT 1"); $coupon_id = tep_db_fetch_array($coupon_query); $couponid = $coupon_id['coupon_id'];

Thank you.

3

Answers


  1. Instead of:

    $couponid = $coupon_id['coupon_id'];
    

    Try:

    $couponid = $coupon_id['coupons_id'];
    
    Login or Signup to reply.
  2. If I remember correctly you can pass on the coupon code through the page, and have access to it. If not, hack into the coupon entry page, and on the “if coupon is ok” part, save it in a session variable. On the success page you`d just use something like $_SESSION[‘couponcode’], no use in having more queries. This is probably 2 lines of modification on the coupon entry page.

    Login or Signup to reply.
  3. My solution is probably a bit more than you’re looking for but worked well for my work. I do a query at around line 76 in this php file that queries out the order information and the coupon code.

    $orders_query = tep_db_query("select orders.orders_id from " . TABLE_ORDERS . " left join discount_coupons_to_orders dco on orders.orders_id=dco.orders_id where customers_id = '" . (int)$customer_id . "' order by date_purchased desc limit 1");
    $orders = tep_db_fetch_array($orders_query);
    

    The purpose of this is so that way a customer can get info on their order. You can reference your coupon code in here like I did showing that the discount was applied.

        echo '<br /><br /><span style="color:red"><b>Your order number is #'.$orders['orders_id'].(!empty($orders['coupons_id']) ? ' Discount Code: '.$orders['coupons_id'] : "").' you can now <a href="account_history_info.php?order_id='.$orders['orders_id'].'" style="text-decoration: underline;color:red">view your receipt</a></b>.</span>';
    

    We found customers immediately want to see a “receipt”, so we link directly back to account history. But the key here is that if you use a join to the main order information you can access the order info and the coupon code in one shot.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search