Skip to content

Instantly share code, notes, and snippets.

@devinsays
Last active July 18, 2023 14:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devinsays/dfdddebda9d3108c0ba1 to your computer and use it in GitHub Desktop.
Save devinsays/dfdddebda9d3108c0ba1 to your computer and use it in GitHub Desktop.
Example of WooCommerce Conversion Tracking in wp_footer
@TorlockC
Copy link

TorlockC commented Jan 7, 2020

Line 7: $price = $order->get_total();

Should be: $order_total = $order->get_total();

Thanks by the way, really helpful code here, just what I needed :)

@devinsays
Copy link
Author

Thanks @forecasty. Updated.

@kdoran55
Copy link

Hello. I need to place the following code onto the Thank You Page (order received) section of WooCommerce. Using the script you provided above how would I get that script into that code?

<script type="application/javascript" src="https://px.octillion.tv/pixel.png?pxid=6436b6c1a606bb0b97ddbbe5&random=4cg10l2aflgdqz264&saleamount=get_total();?>&conversion=1&ordernumber={ordernumber}"></script>

@devinsays
Copy link
Author

@kdoran55

function prefix_service_conversion_tracking() {
	if ( is_order_received_page() ) :
		global $wp;
		$order_id = isset( $wp->query_vars['order-received'] ) ? intval( $wp->query_vars['order-received'] ) : 0;
		$order = new WC_Order( $order_id );
		if ( $order && ! $order->has_status( 'failed' ) ) :
			$order_total = $order->get_total();
			$order_id = $order->get_order_number();
			?>
			<script type="application/javascript" src="https://px.octillion.tv/pixel.png?pxid=6436b6c1a606bb0b97ddbbe5&random=4cg10l2aflgdqz264&saleamount=<?php echo $order_total; ?>&conversion=1&ordernumber=<?php echo $order_id ; ?>"></script>
		<?php
		endif;
	endif;
}
add_action( 'wp_footer', 'prefix_service_conversion_tracking' );

@kdoran55
Copy link

@devinsays thank you so much for this. I thought I had inputted that correctly but looks like I was missing something. Thank you for your help!

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