Filter Search results based on User Group and Products Restrictions
-
We are using Wholesale Suit Plugin,
All our products are only visible/accessible to a particular User Group(s). Meaning when user A who maybe assigned to User Group A will only see products that are restricted to User Group A… he cannot see products set and restricted for another group.
How do we make the search bar only show/return results relevant to their set user group? because at current any user can see all products in the search bar preview…
Fibo Support suggested the following snippet, however, this is requiring us to set an array of product ID’s, we have thousands of products and are continuously adding more products daily, so this snippet is not favourable.
any suggestions to help us achieve such requirement.
TIA.
Fibo Code Snippet for asfw-filters.php file
<?php function return_products_for_roles( $ids ) { require_once( ABSPATH . WPINC . '/class-wp-user.php' ); require_once( ABSPATH . WPINC . '/class-wp-roles.php' ); require_once( ABSPATH . WPINC . '/class-wp-role.php' ); require_once( ABSPATH . WPINC . '/class-wp-session-tokens.php' ); require_once( ABSPATH . WPINC . '/class-wp-user-meta-session-tokens.php' ); require_once( ABSPATH . WPINC . '/capabilities.php' ); require_once( ABSPATH . WPINC . '/user.php' ); wp_plugin_directory_constants(); wp_cookie_constants(); require_once( ABSPATH . WPINC . '/kses.php' ); require_once( ABSPATH . WPINC . '/rest-api.php' ); require_once( ABSPATH . WPINC . '/pluggable.php' ); $user = wp_get_current_user(); $roles = array('A', 'B', 'C'); if (in_array($roles[0], $user->roles)) { return array(1,2,3,4,5,6,7,8,9,10); } else if (in_array($roles[1], $user->roles)) { return array(11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,32,39); } else if (in_array($roles[2], $user->roles)) { return array(33,34,35,36); } } add_filter( 'dgwt/wcas/tnt/search_results/ids', 'return_products_for_roles' );
- The topic ‘Filter Search results based on User Group and Products Restrictions’ is closed to new replies.