Are you looking for add Sales Conversation tracking code to WooCommerce order placed thank you page which is hit only on Order placed ? Well, with a simple few line script (and no plugin) you can achieve it!
No matter whether you’re Tracking code (Conversation) related to Google AdWords, Facebook or related to other marketing ads campaign. If you want your code hit only once Order placed by customer and it is WooCommerce Order thank you page than following script help you to do it without any use any plugin.
add_action( 'woocommerce_thankyou', 'wdo_conversion_tracking_thank_you_page' ); function wdo_conversion_tracking_thank_you_page() { ?> //add your tracking code hereUsing woocommerce_thankyou action it will add your tracking code in Thank you page (order received page) inside tag.
If you want your tracking code must placed inside than you need to use wp_head action instead of WooCommerce woocommerce_thankyou.
add_action( "wp_head", "wdo_thank_you_header_script", 20 ); if ( ! function_exists( 'wdo_thank_you_header_script' ) ) { function wdo_thank_you_header_script() { if ( function_exists( 'is_order_received_page' ) && is_order_received_page()) // check current page is Order Received Page? { ?> // add your tracking code hereif you need to pass Order related details in Conversation code use following code.
How to get the Order ID (Order number ) from the thank you page URL parameters ?
Following code useful for get Order number from the Thank you page Url Parameters
ie. https://domainname.com/checkout/order-received/1234/?key=wc_order_7J49FXyaS12FtjT&utm;_nooverride=1if( ! is_wc_endpoint_url('order-received'))return;
global $wp;
$oid = absint( $wp->query_vars['order-received'] );
if ( empty($oid) || $oid == 0 ) return;
$order = wc_get_order( $oid );$email =$order->billing_email;
$country = $order->get_billing_country();
$date = $order->get_date_created();// add specific day in Order placed Date
$d=7;
$odate = date('Y-m-d', strtotime($date . " +".$d." days"));