Set Up WooCommerce Transaction Tracking
Set up transaction tracking for your WooCommerce store. Learn more about what this integration offers in What is the WooCommerce Integration?
Note Box: You must have your WhatConverts Tracking Code placed in the <head> of the page. If you are using the WhatConverts WordPress Plugin or Google Tag Manager, you will need to deactivate that and place the HTML Tracking Code in the header of your page. You can use a plugin such as Insert Headers and Footers to accomplish this.
Before You Begin
Make sure you have:
- A WooCommerce store with WordPress admin access
- Your WhatConverts tracking script installed in the <head> of your site
- Admin access to install WordPress plugins
Step 1: Install the Code Snippets Plugin
- Download, install, and activate the Code Snippets Plugin.
Step 2: Add the WooCommerce Tracking Code Snippet
- In your WordPress dashboard, hover over "Snippets" and select "Add New" from the menu.
- Give your snippet a name (e.g., "WhatConverts WooCommerce Tracking").
- Paste the following code in the "Code" section:
add_action('woocommerce_thankyou', 'whatconverts_tracking'); function whatconverts_tracking($order_id) { if ($order_id & gt; 0) { $order = wc_get_order($order_id); if ($order instanceof WC_Order) { $completion_date = empty($order - & gt; get_date_paid()) ? strtotime($order - & gt; get_date_created()) : strtotime($order - & gt; get_date_paid()); $current_date = new Datetime(); $time_difference = $current_date - & gt; format('U') - $completion_date; if ($time_difference & lt; 180) { $email = $name = $phone_number = $company = $address_1 = $address_2 = $city = $state = $postcode = $country = ''; if (!empty($order - & gt; get_billing_email())) $email = $order - & gt; get_billing_email(). ' '; if (!empty($order - & gt; get_billing_first_name())) $name. = $order - & gt; get_billing_first_name(). ' '; if (!empty($order - & gt; get_billing_last_name())) $name. = $order - & gt; get_billing_last_name(); if (!empty($order - & gt; get_billing_phone())) $phone_number = $order - & gt; get_billing_phone(); if (!empty($order - & gt; get_billing_company())) $company = $order - & gt; get_billing_company(); if (!empty($order - & gt; get_billing_address_1())) $address_1 = $order - & gt; get_billing_address_1(); if (!empty($order - & gt; get_billing_address_2())) $address_2 = $order - & gt; get_billing_address_2(); if (!empty($order - & gt; get_billing_city())) $city = $order - & gt; get_billing_city(); if (!empty($order - & gt; get_billing_state())) $state = $order - & gt; get_billing_state(); if (!empty($order - & gt; get_billing_postcode())) $postcode = $order - & gt; get_billing_postcode(); if (!empty($order - & gt; get_billing_country())) $country = $order - & gt; get_billing_country(); echo '<script type="text/javascript"> //<![CDATA[ wc_transaction_ypbib ( "'.$order->get_id().'", "'.$order->get_total().'", "'.$order->get_tax_totals().'", "'.$order->get_shipping_total().'", { '; if (!empty($email)) echo '"Email Address": "'.$email. '",'; if (!empty($email)) echo '"Name": "'.$name. '",'; if (!empty($company)) echo '"Company": "'.$company. '",'; if (!empty($address_1)) echo '"Address 1": "'.$address_1. '",'; if (!empty($address_2)) echo '"Address 2": "'.$address_2. '",'; if (!empty($city)) echo '"City": "'.$city. '",'; if (!empty($state)) echo '"State": "'.$state. '",'; if (!empty($postcode)) echo '"Postal Code": "'.$postcode. '",'; if (!empty($country)) echo '"Country": "'.$country. '",'; echo '} ); //]]> </script>'; } } } } - Select "Run snippet everywhere".
- Click "Save Changes and Activate".
Step 3: Verify Transaction Tracking
- Place a test order on your WooCommerce store.
- Complete the checkout process and reach the order confirmation page.
- Log in to your WhatConverts account.
- Access the Lead Manager and look for your test transaction.
- Verify that the transaction amount and marketing attribution data appear correctly.
Related Topics
Get a FREE presentation of WhatConverts
One of our marketing experts will give you a full presentation of how WhatConverts can help you grow your business.
Schedule a Demo