Woocommerce - Hook functions.php来展示产品

时间:2015-10-08 15:50:55

标签: variables filter woocommerce archive

我需要根据传递的变量显示产品。 实施例...

如果我通过: ?的index.php post_type =产物&安培; product_cat =鞋&安培; myfilter =的typeA

如果变量myfilter包含" typeA"我希望归档产品页面显示尺寸为52,53和54的所有鞋子。

我该怎么做? 提前谢谢。

1 个答案:

答案 0 :(得分:1)

由于您有使用pre_get_post的建议,我会给您一个片段,指导您实现目标。您需要更改terms传递的值。

add_action( 'pre_get_posts', 'custom_pre_get_posts_query' );

function custom_pre_get_posts_query( $q ) {

    if ( ! $q->is_main_query() ) return;
    if ( ! $q->is_post_type_archive() ) return;

    if ( ! is_admin() && is_shop() ) {

        $q->set( 'post__in', array( 99, 96, 93, 90, 87,83 ) );
        $q->set( 'cat', 'shoes' );

        return;
    }
}