【问题标题】:Hide out of stock - "pre_get_post" taxanomy for visibility on shop page隐藏缺货 - “pre_get_posts”分类法以在商店页面上可见
【发布时间】:2016-12-21 08:48:21
【问题描述】:

在我的 WooCommerce 商店中,我启用了“从目录中隐藏缺货商品”。此选项会导致各个页面上的产品变体变得不可见

我想仅在存档页面(搜索、类别)上应用“从目录中隐藏缺货商品”选项

这是我的代码:

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

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

我怎样才能做到这一点?

谢谢

【问题讨论】:

    标签: php wordpress woocommerce visibility product


    【解决方案1】:

    试试这个

    您必须检查页面以执行此操作,如下所示

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

    【讨论】:

    • 嗨,我太累了,无法解释实际发生的事情。明天我会回来并清楚地解释我的问题。
    猜你喜欢
    • 2021-08-31
    • 1970-01-01
    • 1970-01-01
    • 2012-11-02
    • 2018-09-01
    • 2021-11-28
    • 2019-07-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多