在首页隐藏某一类别产品

将下面的代码加在函数文件中:


function custom_pre_get_posts_query( $q ) {

  	if( is_front_page() ){
	  $tax_query = (array) $q->get( 'tax_query' );
	  $tax_query[] = array(
			 'taxonomy' => 'product_cat',
			 'field' => 'slug',
			 'terms' => array( 'hidecategories' , 'hidecategories1'), 
			 'operator' => 'NOT IN'
	  );
	  $q->set( 'tax_query', $tax_query );
	}
}


add_action( 'woocommerce_product_query', 'custom_pre_get_posts_query' );  

修改hidecategories及hidecategories1为需要隐藏的类别别名。