add_action('pre_get_posts', function ($query) { if ( ! is_admin() && $query->is_main_query() && ( is_shop() || is_product_category() || is_product_tag() ) ) { if ( ! is_user_logged_in() ) { $query->set( 'post__in', [ 0 ] ); return; } $user = wp_get_current_user(); if ( array_intersect( $user->roles, [ 'administrator', 'tsantakides' ] ) ) { return; } $user_role = $user->roles[0]; $allowed_terms = get_allowed_visibility_terms_by_role( $user_role ); if ( empty( $allowed_terms ) ) { $query->set( 'post__in', [ 0 ] ); return; } $query->set( 'tax_query', array( 'relation' => 'AND', array( 'taxonomy' => 'visibility', 'field' => 'slug', 'terms' => $allowed_terms, 'operator' => 'IN', ), array( 'taxonomy' => 'visibility', 'operator' => 'EXISTS', ), )); } }, 99);