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.

8 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
    Fred

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

    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!

Leave a Reply

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