非常方便的代码段。有时,您只想在商店页面上显示某些类别,而仅将这些产品显示在类别档案下。
add_action( 'woocommerce_product_query', 'bbloomer_hide_products_category_shop' );
function bbloomer_hide_products_category_shop( $q ) {
$tax_query = (array) $q->get( 'tax_query' );
$tax_query[] = array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( 'chairs' ), // Category slug here
'operator' => 'NOT IN'
);
$q->set( 'tax_query', $tax_query );
}