Reputation: 23
I have been trying to implement a "pixel" for the checkout page in woocommerce on a wordpress site with this:
<iframe src="//www.euroads.dk/system/showtrackingpixels.php?cpid=XXXX&sid=1&orderid=%orderid%¤cysymbol=DKK&orderamount=%orderamount%" width=1 height=1 marginwidth=0 marginheight=0 ALLOWTRANSPARENCY="true" frameborder=0 scrolling=no hspace=0 vspace=0></iframe>
I want the %orderid% to get the order id and the %orderamount% to get the total order amount.
i have tried replacing with %orderid% with this
<?php echo $order->id ?>
and the %orderamount% with this:
<?php echo WC()->cart->get_cart_total(); ?>
but it doesn't give the correct result. :(
Can anyone help me?
Upvotes: 1
Views: 3148
Reputation: 41
Add the following code to your theme's function file.
Just Update the basic pieces of the pixel so that it will work with your chosen platform's pixel.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////// ADD TO THE END OF YOUR THEME'S FUNCTIONS.PHP FILE ////////////////////////////////////////
if( ! function_exists( 'add_OfferForge_pixel_code' ) )
{
function add_OfferForge_pixel_code()
{
if( is_order_received_page() )
{
$oid = "11184";// Offer id - o variable
$eid = "183";// event id - e variable
$getid = $_SERVER["REQUEST_URI"];
$uu = explode('/',$getid);
// if -- ["REQUEST_URI"]=> "/checkout/order-received/1689/?key=wc_order_55c9ee479b4c9"
$transid = $uu[3];// order id
$ppppp = $GLOBALS["wp_object_cache"]->cache["post_meta"][$transid]["_order_total"][0]; // price variable with shipping
echo '<iframe src="https://offerforge.net/p.ashx?o='.$oid.'&e='.$eid.'&t='.$transid.'&p='.$ppppp.'&ect='.$ppppp.'" height="1" width="1" frameborder="0"></iframe>';
}
}
}
add_action( 'wp_footer', 'add_OfferForge_pixel_code', 99 );
/////////////////////////////////////////////////////////////////////////////
I hope this works for you.
I used the order total as the amount for both the r and the ect variables.
** If you are placing an OfferForge pixel you will only need to update the 'oid' and 'eid' values.
Upvotes: 0
Reputation: 26309
It has got to be the thankyou page as you do not have an order ID assigned on the checkout. Assuming that you could add your pixel tot he woocommerce_thankyou
hook which is automatically passed the $order_id
variable.
add_action( 'woocommerce_thankyou', 'so_31783715_pixel' );
function so_31783715_pixel( $order_id ){
$order = wc_get_order( $order_id );
$order_total = $order->get_total();
printf( "<iframe src="//www.euroads.dk/system/showtrackingpixels.php?cpid=XXXX&sid=1&orderid=%s%¤cysymbol=DKK&orderamount=%s" width=1 height=1 marginwidth=0 marginheight=0 ALLOWTRANSPARENCY="true" frameborder=0 scrolling=no hspace=0 vspace=0></iframe>", $order_id, $order_total );
}
Upvotes: 5