WooCommerce 是 WordPress 中最强大的商城插件，没有之一。在 [Slearn 主题](https://api.salongweb.com/product/slearn.html)的开发过程中，需要将课程和商城结合，课程使用商城的结算系统，这次又开发了课程打包插件，通过购买一个产品来创建课程订单。

课程打包的产品样式与默认的是不一样，所以想在商城首页排除该分类，使用以下代码即可完美解决：

 ```
/**
 * 在商城首页排除分类下的产品
 */
function salong_shop_exclude_category( $q ) {
	global $salong;
    $tax_query = (array) $q->get( 'tax_query' );
    $tax_query[] = array(
           'taxonomy'	=> 'product-cat',
           'field'	=> 'id',
           'terms'	=> '12',
           'operator'	=> 'NOT IN'
    );
    $q->set( 'tax_query', $tax_query );
}
add_action( 'woocommerce_product_query', 'salong_shop_exclude_category' );
```