Add the following code to your theme’s function.php file, or a functionality plugin to modify the WooCommerce Shop Page in order to prevent specific categories from displaying on the WooCommerce Shop Page.
<?php
/** WooCommerce Hide Cat. */
/** This code should be added to functions.php of your theme or functionality plugin. **/
/** DO NOT INCLUDE THE OPENING <?PHP **/
function custom_pre_get_posts_query( $q ) {
$tax_query = (array) $q->get( 'tax_query' );
$tax_query[] = array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( 'your category' ),
// Hide products from "your category" on the shop page.
'operator' => 'NOT IN'
);
$q->set( 'tax_query', $tax_query );
}
add_action( 'woocommerce_product_query', 'custom_pre_get_posts_query' );
Share Your Two Cents