Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

echo WP ECommerce Product ID After Purchase WordPress

  • SOLVED

I'm trying to set up a third-party revenue tracking script on my wp-ecommerce store, but am having some trouble. I need a way to echo three variables into a script tag on the transaction results page.

My script looks like this:


<script>document.write('<s'+'cript language="JavaScript" src="https://view.atdmt.com/jaction/6jqptv_RevenueTag_1/v3/ato.ORDERID/[atm1.Quantity/atm2.Revenue]"></s'+'cript>')</script>


And what I need to do is echo the Order ID, item quantity, and item cost into the script so that they can be tracked. I've searched through a lot of functions but haven't found a simple way to do this.

ORDERID needs to be replaced with the product ID.
Quantity needs to be replaced with the quantity ordered.
Revenue needs to be replaced with the order total.

Any that's familiar with wp ecommerce have an idea?

Thanks

===========EDIT=============

All I'm really trying to do is store three values in variables:

- the product id purchased
- the number of items ordered
- the total price of the order

If you can help me store those three items in variables on the transaction results page, the prize is yours.

Answers (3)

2011-03-15

AdamGold answers:

Ok.
First, you should add the following code in the form that sends the order, so you will be able to retrieve the variables after sending the form:

<input type="hidden" name="order_id" value="Put here the variable of the order id (before the form is sent)
<input type="hidden" name="order_r" value="Put here the variable of the order quantity (before the form is sent)
<input type="hidden" name="order_q" value="Put here the variable of the order revenue (before the form is sent)

Now, if your form method is POST, this will be your code after the submission:

$order_id = $_POST['order_id'];
$order_quantity = $_POST['order_q'];
$order_revenue = $_POST['order_r'];

If your form method is GET, this will be your code:

$order_id = $_GET['order_id'];
$order_quantity = $_GET['order_q'];
$order_revenue = $_GET['order_r'];


Now, just echo the script in the same PHP file as the above variables:

echo "
<script>
document.write('<s'+'cript language=\"JavaScript\" src=\"https://view.atdmt.com/jaction/6jqptv_RevenueTag_1/v3/ato." . $order_id . "/[atm1." . $order_quantity . "/atm2." . $order_revenue . "]\"></s'+'cript>')</script>
";

2011-03-15

Lee Willis answers:

Your final solution needs to be a bit more complicated than you've suggested. We'd need to know what happens if the cart contains more than 1 item - do you show two sets of the tracking script - one for each item?

Anyway - in PHP you'll want to use the global variable $cart_log_id, and run something like this to get the contents of the cart:

$cart_items = $wpdb->get_results ("SELECT * FROM ".WPSC_TABLE_CART_CONTENTS." WHERE purchaseid = ".$cart_log_id, ARRAY_A);


Then output whatever JS is required.

2011-03-14

Denzel Chia answers:

Hi Pippin,

I am not familiar with wp ecommence. But I would like to provide some ideas.

Are you able to post the content of the script here?
Or are you able to link to the content of script?

The below script that you posted, is just a javascript to write out a javascript link.

<blockquote>
<script>document.write('<s'+'cript language="JavaScript" src="https://view.atdmt.com/jaction/6jqptv_RevenueTag_1/v3/ato.ORDERID/[atm1.Quantity/atm2.Revenue]"></s'+'cript>')</script>
</blockquote>

Normally, you define javascript variable before linking the script.

Try looking into the content of https://view.atdmt.com/jaction/6jqptv_RevenueTag_1/v3/ato.ORDERID/[atm1.Quantity/atm2.Revenue]
and see if there is any variable for you to assign in the order id, quantity, and revenue.

Thanks.
Denzel


Pippin Williamson comments:

I'm not concerned with passing the variables. I know how to do that fine. I'm just looking for a function that will allow me to retrieve the values I'm looking for.

Thanks anyway though.