Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save grayayer/f163b58a4b2f179d2659609a646034e1 to your computer and use it in GitHub Desktop.
Save grayayer/f163b58a4b2f179d2659609a646034e1 to your computer and use it in GitHub Desktop.
this function checks whether the page is the order received page, and if so, checks whether the order contains the bundle product, and if so, outputs the tracking pixel on that page. Put this file in your themes function.php file
/** Add tracking pixel if order contains product ID. Replace 11747 with your specific product ID */
add_action( 'woocommerce_thankyou', 'bundleTracking' );
function bundleTracking(){
/* do nothing if we are not on the appropriate page */
if( !is_wc_endpoint_url( 'order-received' ) || empty( $_GET['key'] ) ) {
return;
}
$order_id = wc_get_order_id_by_order_key( $_GET['key'] );
$order = wc_get_order( $order_id );
foreach( $order->get_items() as $item ) {
if( $item['product_id'] == 11747 ) {
echo '<img src="https://twilightnight.com/p.ashx?a=504&e=518&f=img&t='.$order_id.'" width="1" height="1" border="0" />';
}
}
}
@grayayer
Copy link
Author

it should be noted of course that you''ll want to modify line 16 to include whatever your tracking pixel actually is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment