Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 自定义属性选项的计数_Php_Woocommerce - Fatal编程技术网

Php 自定义属性选项的计数

Php 自定义属性选项的计数,php,woocommerce,Php,Woocommerce,如果产品上有多种颜色可供选择,我想在分类页面上留言“其他颜色可选”。现在我在content.product.php中有一些代码可以检测它是否是一个可变产品,但不能检测一个属性是否有多个选项。颜色是一个自定义属性 现在我有: <?php if($product->product_type == "variable") { ?> <h4>Available in other colors.</h4> <?php } else { ?> &l

如果产品上有多种颜色可供选择,我想在分类页面上留言“其他颜色可选”。现在我在content.product.php中有一些代码可以检测它是否是一个可变产品,但不能检测一个属性是否有多个选项。颜色是一个自定义属性

现在我有:

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

<?php } ?>

有其他颜色可供选择。

它将显示所有可变产品类型,并显示此消息。我想显示它只有当有2个或更多的颜色附加到产品。产品有两个属性-尺寸和颜色。大小总是有三个或四个wheras颜色有时只有一个

我想你是在找这样的东西吧

<?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..
}

这行吗?怎么了?它是干什么的?不知什么原因,它对我不起作用。当我打印时,我从来没有看到任何与颜色有关的东西。颜色的鼻涕虫是色样。