如果未设置变体,则隐藏产品属性 (WooCommerce)
hide product attributes if their variations are not set (WooCommerce)
如果未设置变体,如何隐藏产品属性。示例:我有 3 种不同的颜色和 3 种不同的尺寸。但并非每种颜色都存在每种尺寸:
- 蓝色>>> M
- 黄色 >>> M、L、XL
- 绿色 >>> M、L、XL
即蓝色只有一种尺码(其他变体未在变体中设置)。但是如果有人选择蓝色,他可以选择所有尺寸(应该只看到尺寸 M),然后获取 WooCommerce wc-no-matching-variations 信息。
如果选择蓝色,如何隐藏其他尺寸选项?
我找到了这个,但这不起作用:
Hide variations that don't match Woocommerce
当 WooCommerce 中的变体超过 30 个时,AJAX 将启动并防止列表被过滤。这可以通过将其添加到 functions.php
来修改
function custom_wc_ajax_variation_threshold( $qty, $product ) {
return 10;
}
add_filter( 'woocommerce_ajax_variation_threshold', 'custom_wc_ajax_variation_threshold', 10, 2 );
如果未设置变体,如何隐藏产品属性。示例:我有 3 种不同的颜色和 3 种不同的尺寸。但并非每种颜色都存在每种尺寸:
- 蓝色>>> M
- 黄色 >>> M、L、XL
- 绿色 >>> M、L、XL
即蓝色只有一种尺码(其他变体未在变体中设置)。但是如果有人选择蓝色,他可以选择所有尺寸(应该只看到尺寸 M),然后获取 WooCommerce wc-no-matching-variations 信息。
如果选择蓝色,如何隐藏其他尺寸选项?
我找到了这个,但这不起作用: Hide variations that don't match Woocommerce
当 WooCommerce 中的变体超过 30 个时,AJAX 将启动并防止列表被过滤。这可以通过将其添加到 functions.php
来修改function custom_wc_ajax_variation_threshold( $qty, $product ) {
return 10;
}
add_filter( 'woocommerce_ajax_variation_threshold', 'custom_wc_ajax_variation_threshold', 10, 2 );