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.


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

43 thoughts on “Filter WooCommerce orders by user role

Grace July 15, 2015 at 3:53 pm

Thank you – this helps a lot πŸ™‚ Nicely done Jeroen!
Any thoughts on how to dedicate a row color or icon of some sort to each role in the display for quickly spotting it before filtering?

jeroen July 15, 2015 at 4:09 pm

You’re welcome, happy to help πŸ™‚

I think a icon would be the hardest to do, these are assigned per order status, and I wouldn’t recommend adding new ones just for wholesalers.

A row background color should be able to be accomplished with a bit of CSS and some code creativity, but I haven’t dived into such thing.

Have you been successful in implementing the code? One thing I was kinda bugged by was the long list of unused user roles so I’m curious what your thoughts are on that.


Dale November 23, 2015 at 8:45 pm

Hi Grace, here is a snippet of code that you can add to your theme’s functions.php file to add custom row colors based on customer’s role:

Jordan October 27, 2015 at 12:20 pm

Hi, i have a problem with this code.
This il looking for “post_author” id but in my case, all the orders have the same post_author value (1). How can i fixe it to have the customer id in that fiel instead of 1 (maybe the admin value).

Sorry for my bad english πŸ™‚

jeroen October 30, 2015 at 9:24 am

Hi Jordan,

This is a very specific code snippet. If you want to modify the purpose to something it is possible but may require a bit more work.
If you want to get the orders of one specific user, you can do that already by default in WooCommerce (edit a order, and click the ‘View other orders β†’’ button). It uses a URL parameter to select all those users (so you won’t need all of the code in the code snippet).


Dale Higgs November 23, 2015 at 7:46 pm

Jordan, I had the same issue. All of my WooCommerce orders had the post_author as “1” instead of being the customer’s user ID. Here is a modified version that uses the “_customer_user” meta field instead of post_author:

Jereon, this modified version also includes the added feature of hiding all of the unused user roles. πŸ™‚

jeroen November 24, 2015 at 3:39 pm

Looks great from here Dale!

Haven’t tested it yet, but how is the performance on the order count query? If you have a ton of orders I guess this can be just a cinch slow(ish). How about adding a LIMIT 1 (as you only want to know its not empty, right?) ?


Deb January 22, 2016 at 9:56 am

Hi Jeroen

I wonder if you could help? I have tried adding this code and although it worked to add in the dropdown filter, the filter itself wouldn’t work to show the orders for the selected role. It either showed no results or seemed to jump to show the Products list
Any help would be appreciated
Thanks in advance

jeroen January 22, 2016 at 11:13 pm

Hi Deb,

It didn’t seem to work, and I just made some changes to the code posted on the page, which should fix things.

Let me know how things work out for you πŸ™‚


Kenneth Vigue January 22, 2016 at 10:03 pm

Good afternoon!
Does this still work with the newest version of WordPress? I copied and pasted the code correctly but when I filtered by user role…it returns no values.

jeroen January 22, 2016 at 10:29 pm

Hi Kenneth,

I’ve just tested this on WP 4.4.1 and WC 2.5 and it works over here.
Are you sure you’ve selected a user role that has orders?


jeroen January 22, 2016 at 11:14 pm

Hi Kenneth,

I spoke to soon,, it indeed didn’t work, but I just made some changes that should fix everything. Re-copy the code snippet and you should be good to go πŸ˜‰


Kenneth Vigue February 2, 2016 at 8:28 pm

Hey Jeroen:

I copied the new version…but it’s still not returning any values? The user roles are set correctly. Is it possible to contact you to take a look?

– Ken

jeroen February 3, 2016 at 9:51 pm

Hi Ken,

What WP / WC versions are you using?
What are the user roles you’re using?
Is it not showing any results at all, or are they not filtered correctly?


Ari June 14, 2017 at 8:18 pm

Hi Jeron, I would love to use your snippet but don’t know how to I create a user role that is connected to specific orders. Could you help me with that and then I can use your code to filter?

Jeroen June 15, 2017 at 8:42 am

Hi Ari,

The filtering is based on the user role of the customers that have made an order. The user roles are thus based on the customer of said order.

If you want to create a new user role I’d advise a plugin like User Role editor.


Donna January 23, 2016 at 1:14 am

Hi Jeroen,

Is there anyway I can set-up the orders page in the back end of Woomerce to filter the different pick-up locations. I have plugged in the Local Pick-ups Plus as we have multiple pick-up locations (no shipping) and I would like the staff at the different stores to only see their orders not all orders?

I am also looking for the best option to display a build you own sandwich option
in our online store. I have installed product bundles and composite products but it is a bit clumsy or is it just my config?
Do you have a plugin that works for this application. Ultimately I would like customers to just choose the options they want, the composite (stepped) config makes you choose every component even though it is ticked optional otherwise it wont let you proceed to the next component. Is this just my crappy set-up? and maybe I could get a developer to configure this properly?
The sandwich options have a lot of variable products included such as three type of lettuce, 10 breads….


jeroen January 23, 2016 at 5:53 pm

Hi Donna,

It is possible to setup a filter based on the pick-up locations, but that does require quite some changes as per the code snippet on this page (but is would be a good base).

Re sandwich builder:
It would all depend on your exact needs. I think these plugins may fit your needs:

If you’d like to talk further about this, feel free to contact me: πŸ™‚


Deb January 24, 2016 at 10:08 pm

Hi Jeroen
Just tried the rewritten version, but still not working unfortunately. Would it be better to contact you directly?


Adam January 26, 2016 at 6:37 pm

Hi I have just tried this piece of code both in my funtions.php file and as a plugin and its causing a fatal error on line 35

Parse error: syntax error, unexpected ‘<' in /var/www/vhosts/ on line 35

jeroen January 27, 2016 at 10:10 am

Hi Adam,

My best guess is that you copied too much of the code snippet into that script..
If you copy it into an existing script you shouldn’t include the `<?php` part.

(I wrote a peace about code snippets some time ago: in case you need more assistance with it.

Hope that fixes things for you πŸ™‚

PN March 15, 2016 at 10:42 pm

This piece of code has been of immense help, thanks Jeroen!

Mike Hemberger October 21, 2016 at 9:50 pm

Super cool, thanks for this! Working well as of WP 4.6.1 and Genesis 2.4.2.

Sandeep Tete September 16, 2017 at 10:07 pm

Is there a way i can replicate the order page for wc-vendor users backend.
Because there are some functionalities i want the vendors to use as well.

Jeroen October 4, 2017 at 2:22 pm

Hi Sandeep,

This is possible, but does require way more efforts then what is described in this blog.
You’d want to hire a developer to help out with that if you’re not sure how to do it.


Johannes October 27, 2017 at 2:23 pm

Hi, thank you for this code. Is it possible to do similar with a custom user meta field as the sorting field?


Jeroen October 27, 2017 at 6:31 pm

Sure Johannes!

Just modify the script to your needs to use a meta field instead, shouldn’t be too much work to do so. You can use the snippet as a starting basis.

Johannes October 27, 2017 at 9:27 pm

Hm…than you Jeroen. I am afraid I am not able to do this. If my cusom filed is pods_meta_kundenummer, where in the code shall I set it?

Lakhmi Chand November 12, 2017 at 11:27 am

Hello, thank you very much, it is of interest to me. How could I do to show only the user roles that I choose? I want you to show only 3 roles. Thank you

Jeroen November 12, 2017 at 10:20 pm

Hi Lahkmi,

You can do this by editing the code from line #11, this is where the roles are inserted which can be selected.


Mandeep May 17, 2018 at 7:57 pm


Your code is perfect. Thank you!!

I need some different option. I am having website with the tours from various supplier.
I want orders to filter according to suppliers. For example I have one supplier xyz and xyz having 10 tours. So I want to filter orders only for xyz supplier. In other words I want to filter orders that are only from those 10 tours.

Website link :

Thank you

daman June 12, 2018 at 2:35 pm

Hi jerone,
Can you please tell me , How can i search orders by user id in woocommerce backend orders ?

Jeroen Sormani June 13, 2018 at 8:42 am


You can search on user ID with the WooCommerce Core ‘Filter by customer’ functionality.

viki June 21, 2018 at 9:34 am

Hi Jeroen,

Can you please tell me , How can i added other user role order page filter options on backend orders ?

Lyse November 30, 2019 at 5:55 pm

Great function and thank you for sharing.
How would I only display specific roles in the dropdown list? For example, only select these roles: customer, wholesale customer, wholesale distributor, wholesale silver, wholesale gold, wholesale premium, wholesale union, sponsored

Can’t seem to make this work.
Thank you

Jeroen Sormani January 19, 2021 at 8:16 pm

Hi Lyse,

Its possible to do this, but would require some changes. You can enter a manual list (array) of the user role as the $user_roles variable in the first function.

Miguel Angel May 16, 2020 at 5:43 pm

Thank you very much!

Nik Rivas-Barnao September 2, 2020 at 6:07 pm

Thanks! This code still works well. The only bug it has is if you allow guests to checkout you cannot search for their orders, it always returns nothing found.

Any ideas on how it can still allow the standard guest search function?

Jeroen Sormani January 19, 2021 at 8:14 pm

Hi Nik,

A bit late reply, but I’ve updated the code to include guests in the dropdown and ensured this works when filtering!

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.

Leave a Reply