首页 文章

隐藏缺货 - “pre_get_post”taxanomy以获得商店页面的可见性

提问于
浏览
0

在我的WooCommerce商店中,我启用了"Hide out of stock items from the catalogue" . 此选项会导致 product variations on individual pages to become invisible .

我想申请"Hide out of stock items from the catalogue"选项 only on archive pages (search, categories) .

这是我的代码:

function featured_posts( $query ) {
    if ( ! $query->is_main_query() ) return;

    //What goes in here?
}
add_action( 'pre_get_posts', 'featured_posts' );

我怎样才能做到这一点?

谢谢

1 回答

  • 0

    试试吧

    你必须检查页面,如下所示

    function featured_posts( $query ) {
    
        if(is_product_category() || is_search()){
            if ( ! $query->is_main_query() ){
                return;
            }
        }
        ....
    }
    add_action( 'pre_get_posts', 'featured_posts' );
    

相关问题