自定义属性选项的计数


Count of Custom Attribute Options

如果您想在

产品上选择多种颜色,我想在类别页面上添加一条消息说"有其他颜色可供选择"。现在我在content.product中有一些代码.php可以检测它是否是可变产品,但如果一个属性有多个选项,则不能检测。颜色是自定义属性。

现在我有:

<?php if($product->product_type == "variable") {  ?>
<h4>Available in other colors.</h4>
<?php } else {  ?>
<?php } ?>

它显示带有此消息的所有可变产品类型。我只想仅在产品上附加了 2 种或更多颜色时才显示它。产品有两个属性 - 尺寸和颜色。尺寸总是有三到四种颜色有时只有一个

我想你正在寻找这样的东西?

<?php
if ($product->product_type == "variable") {
    print '<h4>Variable products message.</h4>';
}
else if (count($product->color) > 2) {
    print '<h4>This product is avilable in other colors!</h4>';
}
else {
    #Optional print here..
}
?>

我可能是错的,你需要做的就是通过写作进行测试

<?php print_r($product); exit;?>

查看颜色的存储位置,只需将->color替换为正确的名称即可。祝你好运!

这就是最终工作的原因

    <?php
$fabric_values = get_the_terms( $product->id, 'pa_color-swatch');

if (count($fabric_values) >= 2) {
    print '<h4>Available in other fabrics.</h4>';
}
else {
    #Optional print here..
}

?>