要想从woocommerce商店页面中的特定类别中排除产品,可以使用以下代码:

/**  * Remove products from shop page by category  *  */ function woo_custom_pre_get_posts_query( $q ) { if ( ! $q->is_main_query() ) return; if ( ! $q->is_post_type_archive() ) return; if ( ! is_admin() && is_shop() ) {  $q->set( 'tax_query', array(array( 'taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => array( 'shoes' ), 'operator' => 'NOT IN' ))); }  remove_action( 'pre_get_posts', 'custom_pre_get_posts_query' ); } add_action( 'pre_get_posts', 'woo_custom_pre_get_posts_query' );

 

将PHP代码放在主题或子主题functions.php文件的底部。

www.npspro.cn软师兄
软师兄 » 如何在woocommerce商品页中排除某些分类的产品
50T免费网盘资源大集合【持续更中~~~~】:点击查看