Last active
July 18, 2023 14:27
-
-
Save devinsays/dfdddebda9d3108c0ba1 to your computer and use it in GitHub Desktop.
Example of WooCommerce Conversion Tracking in wp_footer
Thanks @forecasty. Updated.
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>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' );
@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
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 :)