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
Instead of:
Try:
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.
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.
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.
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.