Imagine that we have an online store, but that, many of the products in our catalog do not want to appear on the cover of it.

Yes, we want them to be indexable on Google, and that they are accessible to users, but not from the front page of the store. So, How do we do this?

This can be easily done from function.php file.

How to Hide product categories in your store

Let’s go to functions.php of our active theme, and we add the following function:

add_action( 'woocommerce_product_query', 'prefix_custom_pre_get_posts_query' );

function prefix_custom_pre_get_posts_query( $q ) {
	
	if( is_shop() ) { //No se mostrarán en estas páginas
	 $tax_query = (array) $q->get( 'tax_query' );
	
	 $tax_query() = array(
	  'taxonomy' => 'product_cat',
	  'field' => 'slug',
	  'terms' => array( 'productos-fotos', 'cat2' ), // Categorías que no mostraremos
	  'operator' => 'NOT IN'
	 );
	
	
	 $q->set( 'tax_query', $tax_query );
	}
}

Where:

if( is_shop() ) {

They will be the pages where we are not going to show the products. In this case, in the store (shop). But we can also put as many as we want. Ex:

if( is_shop() || is_page('awards') ) {

On the other hand, in the array, we will specify the category or categories that will contain the products to be hidden. In our example, the products in the categories will not be displayed: products-photos, cat2

'terms' => array( 'productos-photos', 'cat2' ),

And what can this do for us?

Well, for example, to create landing pages specific of specific products.