需要帮助使用"if"和"empty"以及"echo" Magento



对不起,我只是自学成才,但有些事情有问题。

我目前有一个自定义属性,仅当该属性没有值时,我才想回显价格。 这就是我现在拥有的,但目前两者兼而有之。 这是针对产品列表.phtml页面的。在过去的 3 个小时里一直在试验,不知道该怎么做。

<div class="product-pricerange" id="product-pricerange">
   <?php echo $_product->getResource()->getAttribute('pricerange')->getFrontend()->getValue($_product) ?>
</div>
   <?php echo $this->getPriceHtml($_product, true) ?>

提前感谢,因为任何帮助都非常感谢。

您应该能够通过将其包装在 IF 语句中来实现这一点,如下所示:

<div class="product-pricerange" id="product-pricerange">
    <?php if(!$_product->getData("your_attrubute")):?>
        <?php echo $this->getPriceHtml($_product, true) ?>
    <?php endif;?>
</div>

你也可以

使用 hasData() functionnality

<div class="product-pricerange" id="product-pricerange">
  <?php if($_product->hasPricerange()):?>
    <?php echo $this->getPriceHtml($_product, true) ?>
  <?php endif;?>
</div>

相关内容

最新更新