我在 WooCommerce 上开一家鞋店。每双鞋都有不同的颜色和尺码。我添加了颜色和尺寸作为属性,然后添加了一些产品作为可变产品。
我想在商店页面中列出所有产品,仅包括颜色变化(不包括尺寸!)...示例:
然后,我的商店页面应该有四个项目:
第一步:我试图以商店页面主查询为目标来修改它,但我不能!我正在这样做:
function custom_pre_get_posts( $query ){
// attempt #1
if( ( 'product' == get_post_type() || is_post_type_archive('product') ) ):
$query->set( 'posts_per_page', '1' );
return;
endif;
// attempt #2
if( is_shop() ):
$query->set( 'posts_per_page', '1' );
return;
endif;
}
add_action('pre_get_posts', 'custom_pre_get_posts');
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?提前致谢!
第二步:我将尝试修改主查询以仅针对我之前提到的变体...我也不知道如何做到这一点...有任何提示吗?
谢谢!!