ok, I added the sorting of categories, specified the category id in the exceptions, but still the products fall into the general list of products
Here is the code that removes the selected category from the list of products. I need the same thing from the plugin. If it helps.
function exclude_category_for_guests($query)
{
if (! is_admin() && $query->is_main_query() && (is_shop() || is_product_category() || is_product())) {
if (! is_user_logged_in()) {
$tax_query = $query->get('tax_query');
if (! empty($tax_query)) {
$tax_query[] = array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => 'selected_category',
'operator' => 'NOT IN',
);
} else {
$tax_query = array(
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => 'selected_category',
'operator' => 'NOT IN',
),
);
}
$query->set('tax_query', $tax_query);
}
}
}
add_action('pre_get_posts', 'exclude_category_for_guests');