将如下代码加入到主题的functions.php文件
/*@JUCUBE.COM 在商店产品页面不显示指定分类目录 */ function custom_pre_get_posts_query( $q ) { $tax_query = (array) $q->get( 'tax_query' ); $tax_query[] = array( 'taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => array( 'fenlei1','fenlei2' ), // 在商店页面不显示指定分类目录,填写别名 'operator' => 'NOT IN' ); $q->set( 'tax_query', $tax_query ); } add_action( 'woocommerce_product_query', 'custom_pre_get_posts_query' );
其中fenlei1
和fenlei2
是需要指定在商品页面不显示的分类目录别名,该功能非常适合用于woocommerce出售课程结算以及活动票务的主题。