In WooCommerce I have checked the option "Visibility out of stock", but I need that some product category stay visible, even if that option is checked.
On the other hand, the main store doesn't show that category. For that I used this code:
add_action( 'pre_get_posts', 'custom_pre_get_posts_query' );
function custom_pre_get_posts_query( $q ) {
if ( ! $q->is_main_query() ) return;
if ( ! $q->is_post_type_archive() ) return;
if ( ! is_admin() && is_shop() ) {
$q->set( 'tax_query', array(array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( 'MYCATEGORY' ), // Don't show this category.
'operator' => 'NOT IN'
)));
}
remove_action( 'pre_get_posts', 'custom_pre_get_posts_query' );
}
As it would be possible to do this?
Thank you!