Woocommerce - 挂钩 functions.php 以显示产品
Woocommerce - Hook functions.php to show products
我需要根据传递的变量显示产品。
示例...
如果我通过:
index.php?post_type=产品&product_cat=鞋子&myfilter=typeA
如果变量 myfilter 包含 "typeA"。
,我希望存档产品页面显示所有尺寸为 52、53 和 54 的鞋子
我该怎么做?
提前致谢。
由于您有一些使用 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;
}
}
我需要根据传递的变量显示产品。 示例...
如果我通过: index.php?post_type=产品&product_cat=鞋子&myfilter=typeA
如果变量 myfilter 包含 "typeA"。
,我希望存档产品页面显示所有尺寸为 52、53 和 54 的鞋子我该怎么做? 提前致谢。
由于您有一些使用 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;
}
}