Excludes products of a category to people not connected or Customer
-
Hello,
I hope you are well.I found this code on another forum post but unfortunately it doesn’t work for me.
I want to do that people who are neither Administrator or Anim, can’t see the products of the Anim category in the search.
If I put it like this, the visitors see the products but not the Administrators or Anim.
add_filter( 'dgwt/wcas/search_query/args', function ( $args ) { $args['tax_query'][] = array( 'taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => array( 'animatrices' ), 'operator' => 'NOT IN' ); return $args; } );
I tried to do this:
add_filter( 'dgwt/wcas/search_query/args', function ( $args ) { global $woocommerce; $user = wp_get_current_user(); $allowed_roles = array( 'customer','subscriber'); if (array_intersect( $allowed_roles, $user->roles) || (!is_user_logged_in)) { $args['tax_query'][] = array( 'taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => array( 'animatrices' ), 'operator' => 'NOT IN' ); return $args; } } );
But it doesn’t show the products below the categories anymore.
There is really something I don’t understand.
Do you have a clue?
Thank you very much for your help.
Carole
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Excludes products of a category to people not connected or Customer’ is closed to new replies.