I am trying to hide all Woocommerce products from a specific product category on the main shop archive page (products only visible when a customer goes to the specific category archive).
The following code is working to hide those products in my original language (Dutch), but not in the other 3 site languages, even though I also added their correct category id's.
add_action( 'woocommerce_product_query', 'prefix_custom_pre_get_posts_query' );
function prefix_custom_pre_get_posts_query( $q ) {
if( is_shop() || is_page('shop') ) { // set conditions here
$tax_query = (array) $q->get( 'tax_query' );
$tax_query[] = array(
'taxonomy' => 'product_cat',
'field' => 'term_id',
'terms' => array(27,952,951,1119), // set product categories here
'operator' => 'NOT IN',
);
$q->set( 'tax_query', $tax_query );
}
}
Anyone knows how I could adapt this code snippet so it works in all languages? Thanks!