There are a lot of people who use WooCommerce to sell their products to customers and wholesalers. For those people who are it would be nice to be able to display all orders that are made by wholesalers or customers separately.
In this post I will show you how you can easily add a new drop down to filter by user role, just next to the ‘Search for a customer’ drop down in the order overview in the admin.
Adding a piece of code
In order to create the drop down, and the functionality to filter the orders on user role, I’ve created a piece of code that can be added to your themes functions.php. Its best to add it there as it are only two functions, and not really worthy of creating a plugin if you just want to use this functionality. Of course feel free to create a separate plugin if you want to π
Thats it!
That will do everything you will need to add a drop down to the shop order admin area of WooCommerce.
59 thoughts on “Filter WooCommerce orders by user role”
Weirdly I’m facing the same issue that Kenneth faced where the drop down menu for the filters is coming up but when a role is selected, no order data is getting displayed at all.
Hi AJ,
I’ve just tested the script and it should still work. Unfortunately I don’t have any top of the head debug tips that I can provide without knowing in-depth details about the setup / what/why this is happening.
Hey man! Just wanted to thank you for this. This is exactly what my client wanted and it works perfect.
Hello, I am trying to change the customer user role from the order page. Is it possible to change the customer’s user role from Edit order page? Please advice. Thanks in advance.
Hi,
Of course its possible, just not with this code snippet in this blog, you’d need something completely different to change user role from the order page.
Cheers,
Jeroen
Hi Jeroen,
Your are realy awesome, thanks a lot for this piece of code !!
Have a nice day and thanks again π
Amazing, thank you, life saver for a B2B shop!
This works perfectly, thank you.
Is it possible to tweak the code to show in a few additional locations via WP admin?
– WooCommerce > Analytics > Orders > Users column (next to customer name and customer type)?
– WooCommerce > Analytics > Overview > Leaderboards > Top products by user role
Or to simplify this, with your current code, what if instead of only a dropdown, the column of orders has user role added. So under screen options, you could enable “User Role” with the defaults: Order Date, Status, Total Spent, Billing , Ship to Total, Actions
Thank you!
Hi Ash,
This is not a simple tweak, it would require a completely new/different customization to modify the analytics reports like that..
Cheers,
Jeroen
This is A_M_A_Z_I_N_G
thank you
Congratulations on this amazing article.
Thank you I found your blog, and your different works.
I want to add a filter like this but to the ADVANCED FILTERS section of WordPress Analytics, in the orders section.
I imagine you know which section I mean
Well, my idea is to add the filter there, to be able to distinguish the orders of the wholesale customers from the orders of the rest of the customers.
Can you tell me what WordPress functions or filters I can use to achieve this?
Thank you
Hi Miguel,
The filters there are quite a bit different from the on in this post. I do have something planned for the reports over there, but don’t have it ready just yet π
Cheers,
Jeroen
hi
how we can show user role in each order row in order list?
Hi,
You’d need a different kind of code for this, unfortunately that is out of scope for this blog post.
Hi, I think the code is not working anymore, I mean, put in function,php, no errors, but once I use it, the same list of orders are displayed for every role I apply the filter… PW version 6.4.2 WC 7.5.1… thanks
Hi Angelo,
Just gave this snippet a test run and it seems to work for me on Woo 8.1
Cheers,
Jeroen
Thank you for this article. I have worked with it for many years, but unfortunately it no longer works as soon as I use the function “Data storage for orders” – Powerful storage of orders (recommended) from Woocommerce.
Do you have a solution for this?
Hi Lina,
Unfortunately I haven’t tested/modified this for HPOS. As it is an entirely new build screen and no longer using posts as before its understandable it won’t work out of the box and would need to be rewritten for the new system.
Cheers,
Jeroen
hello, thanks for this code, how can I integrate it into the product list? I assign the products to a role, I would like to add a filter.
I use the plugin
“Product Visibility by User Role for WooCommerce”