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.

woocommerce-filter-orders-on-user-role

Jeroen Sormani

I'm a professional WordPress plugin developer on a mission to create the best plugins for my clients. I'm specialised in developing general WordPress, WooCommerce and Easy Digital Downloads plugins.

Interested in talking about a WordPress project? Get in touch!

Follow me on Twitter

49 thoughts on “Filter WooCommerce orders by user role

AJ January 19, 2021 at 6:50 pm

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.

Jeroen Sormani January 19, 2021 at 8:01 pm

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.

Daniel Ch May 10, 2021 at 3:26 pm

Hey man! Just wanted to thank you for this. This is exactly what my client wanted and it works perfect.

Sivaji June 21, 2021 at 9:03 am

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.

Jeroen Sormani June 21, 2021 at 9:40 am

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

Kevin October 8, 2021 at 10:20 am

Hi Jeroen,

Your are realy awesome, thanks a lot for this piece of code !!

Have a nice day and thanks again ๐Ÿ™‚

Paul Botwid October 18, 2021 at 11:50 am

Amazing, thank you, life saver for a B2B shop!

Ash E. March 24, 2022 at 6:00 pm

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!

Jeroen Sormani March 25, 2022 at 9:53 am

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

Leave a Reply