Advertisement
xah

logged in users

xah
Jun 22nd, 2020 (edited)
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.58 KB | None | 0 0
  1. // Hide some products from unlogged users and a specific product category
  2. add_filter( 'woocommerce_product_query_tax_query', 'exclude_products_fom_unlogged_users', 10, 2 );
  3. function exclude_products_fom_unlogged_users( $tax_query, $query ) {
  4.     // On frontend for unlogged users
  5.     if( ! is_user_logged_in() ){
  6.         $tax_query[] = array(
  7.             'taxonomy'  => 'product_cat',
  8.             'field'     => 'slug',
  9.             'terms'     => array('t-shirts'), // <=== HERE the product category slug
  10.             'operator'  => 'NOT IN'
  11.         );
  12.     }
  13.     return $tax_query;
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement