Add Referrer info to WooCommerce order

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.

13 thoughts on “Add Referrer info to WooCommerce order

  1. 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

    1. 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 );


  2. 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 ‘’.

    Am I doing something wrong? I implemented your snippet on a clean WordPress install, with a (clean) child-theme and only WooCommerce enabled.

    1. 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!

  3. 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

  4. 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?


  5. 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.


Leave a Reply

Your email address will not be published. Required fields are marked *