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

59 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

Cintia Bender Lima March 6, 2023 at 1:51 pm

This is A_M_A_Z_I_N_G
thank you

Miguel Espeso May 14, 2023 at 2:05 pm

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

Jeroen Sormani May 15, 2023 at 9:47 am

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

nimakh December 31, 2023 at 3:28 pm

hi
how we can show user role in each order row in order list?

Jeroen Sormani January 3, 2024 at 10:03 am

Hi,

You’d need a different kind of code for this, unfortunately that is out of scope for this blog post.

Angelo January 18, 2024 at 2:27 pm

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

Jeroen Sormani January 19, 2024 at 11:24 am

Hi Angelo,

Just gave this snippet a test run and it seems to work for me on Woo 8.1

Cheers,
Jeroen

Lina February 17, 2024 at 3:57 pm

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?

Jeroen Sormani February 19, 2024 at 10:30 am

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

simo February 21, 2024 at 12:32 pm

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”

Leave a Reply