Here’s another quick code snippet for you all, this time to keep track of where a customer initially came to the site from when they make an order via WooCommerce.
This is great for tracking any marketing efforts that you are doing and a quick and easy way of seeing how your users are interacting with your site.
The data will then appear in the meta boxes of an order, so you can find out where they came from.
where can I put this code?
Hi there,
There are a few ways of doing it:
1) Drop it into the functions.php of your child theme (if you’re not using a child theme check out what it does and how to set it up here)
2) Create a plugin for yourself (here’s some instructions on how to make a quick one)
Hi there,
Thank you for this greate snippet 🙂
Could you please tell me how I can see the referrer on the woocommerce email that i receive instead of having to go to the meta boxes of an order?
Thank you
Fred
You’re welcome Fred!
You can use this snippet here in your functions.php to add it to the email you get when an order comes through:
add_action( "woocommerce_email_after_order_table", "show_wc_referrer_after_order_table", 10, 1);
function show_wc_referrer_after_order_table( $order ) {
echo 'Referrer :'. get_post_meta( $order->id, "referrer", true );
}
I really like the idea of tracking the origin of customers in WooCommerce. I was actually trying to add a hidden Contact Form 7 field with a Referrer Input. But I don’t know how to combine Contact Form 7 and Woocommerce so that the field is part of an order. So, I was really happy to find this page, but when I add your code to my functions file, the referrer that’s shown in the e-mail and orders, is always ‘mydomain.com/wp-admin/post.php?post=9&action=edit’.
Am I doing something wrong? I implemented your snippet on a clean WordPress install, with a (clean) child-theme and only WooCommerce enabled.
Hey Ben,
Generally when you get the problem you’re having it’s because you are testing whilst logged in. If you log out of WordPress and preferably go into another browser or private/incognito window then you should see the behaviour of orders as it would be for users.
Let me know if this helps!
You are totally right, I went in to another browser, made sure I wasn’t logged in, and it works like it should. Thank you!
You’re very welcome! 🙂
Hi there, I tried the code to see it in orders along with seeing it in emails however, I do not see the referrer in either places.
I logged out of the admin and used a different browser. Am I doing something wrong? Is it because I already have a cookie from the website?
Thank you kindly
Tanya
Hello there, hope you are doing well.
I tried applying your code to the child theme function file but I still cannot see the referrer in the order or the email.
I logged out of the admin and tested from a different browser, even deleted my cookies.
Still, can’t see it
Am I doing something wrong?
Sincerely
Tanya
Hi Tanya, thanks for getting in touch. What version of WordPress and WooCommerce are you using and I can test to see if there are any issues?
Hi Steven
This looks like it is exactly what I need. I have a customer who offers services in many locations and each one has its own unique sales page. They have done a deal with a certain hotel and now we are hoping to be able to track any bookings that will be made with an initial link from the hotel website, because a small commission will need to be paid.
From what I can gather, this will allow us to generate a list of sales that have originated from the hotel website. Would this be correct?
This is a WordPress site with WooCommerce and the Bookings extension.
regards
Hi Damien,
Yes that should work, you’d need to put together some code to generate the list of sales from the website based on the post meta data but that should be easy enough!