隐藏Woocommerce商店页面中多个类别的产品

时间:2020-03-14 14:13:18

标签: woocommerce

通过将以下代码段添加到functions.php中,我在商店页面上隐藏了某个类别的产品。这会在商店页面上隐藏产品,但会在类别页面上显示它们。

我现在也想从另一个类别中隐藏。如何将此新类别添加到代码中?我尝试过:

'terms'=> array('verkocht','sale'), =>但这在商店页面上有效,但也从其类别页面隐藏产品,并显示一条消息,指出“否正在显示匹配的产品”。

    /**
 * Exclude products from a particular category on the shop page
 */
function custom_pre_get_posts_query( $q ) {

    $tax_query = (array) $q->get( 'tax_query' );

    $tax_query[] = array(
           'taxonomy' => 'product_cat',
           'field' => 'slug',
           'terms' => array( 'verkocht' ), // Don't display products in the sale category on the shop page.
           'operator' => 'NOT IN'
    );


    $q->set( 'tax_query', $tax_query );

}
add_action( 'woocommerce_product_query', 'custom_pre_get_posts_query' ); 

0 个答案:

没有答案