Learn how to create search results filters based on current user roles.
In this article, we will cover how to create a search results filter based on the current user’s role.
This feature is available in the Advanced Woo Search PRO plugin, allowing you to filter search results based on various parameters.
This can be very useful if, for example, you want to show certain products only to logged-in users while hiding them from everyone else.
Search results for logged-in users
Search results for non-logged-in users
Example: We want to display all products in the Private category only to users with the Customer role and hide them from everyone else.
To create this filter, follow these steps:
1. Open the plugin settings page and go to the Search Results tab.
2. Scroll down to the Filter Results section.
Filter Results section
3. Click on Filter products search results to create a new filtering rule.
4. Set up the following rule:
Current user role -> not equal to -> Customer AND
Product category -> not equal to -> Private
OR
Current user role -> equal to -> Customer
Filtering rules
5. Save the settings and test your search results.
That's it! Now, products in the Private category will only be visible to users with the Customer role.
Search results for users with Customer role
Search results for users without Customer role