As businesses start to grow, business owners work on improving user retention, as such it is crucial to have visibility of your most loyal customers to narrow down some of your targeting groups.
Although WooCommerce Dashboard has exposed a lot more data relating to your orders, it does require the admin user to trawl through reports and this is of course time consuming. When you receive a high volume of orders a day, spending additional effort to understand whether you are serving a new or returning customer is wasted time.
For one of my businesses, I wanted to easily identify how many orders someone had already made with us whilst I am fulfilling each order. I looked online and struggled to find a clean solution readily available that did not need yet another plugin. I stumbled across a snippet on stack overflow but this was mainly for cancelled orders, so I’ve made a few changes to accommodate for my own requirements.
Essentially, there are two use cases below which hopefully will help you and save you time. Each of these spinets goes in your functions.php file and before you go messing with it, make sure you backup your website.
Display total number of completed orders based on customer ID
The above use case however wouldn’t be the best approach for my business as we offer the ability to checkout as a guest; also, majority of our orders come through as guests. We needed to narrow the count to billing email address, this way you will always cover whether the user is an existing customer or not. It does rely on your customers using the same billing email address when placing sub-sequential orders but 9 out 10 times this will be the case.
Display total number of completed orders based on billing email address
With any of these code snippets, it mainly counts the number of completed orders, but as the post_status is an array, you can include other statuses if you want to. Say you want it to count both completed and processing orders then simply extend the post_status array to
If however, you wish to get the count of cancelled orders by customer ID, the post I stumbled across in stack overflow will help you and you can see it here.