magento 2 empty attribute hide in product details page

喜欢而已 提交于 2019-12-24 07:11:13

问题


Magento 2 experts, Can you please help me, to hide empty/NA attribute in magento 2 products details page ?

Thanks a lot


回答1:


Well, This is magento core issue: https://github.com/magento/magento2/issues/9961 , But you can use following solution for now.

Get to attributes.phtml file from :/vendor/magento/module-catalog/view/frontend/templates/product/view/attributes.phtml

Copy this file and paste in your theme : /app/design/frontend/[YOUR PACKAGE]/[YOUR THEME]/template/catalog/product/view/attributes.phtml.

Search following code:

  <tr>
        <th class="label"><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th>
        <td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
  </tr>

Replace above code by the following code:

   <?php
         $_attribute = $_product->getResource()->getAttribute($_data['code']);

         if (!$_attribute->getFrontend()->getValue($_product)) {
            continue;
        }
   ?>

  <tr>
        <th class="label"><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th>
        <td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
  </tr>

Above solution is working perfectly in Magento 2.2



来源:https://stackoverflow.com/questions/44684391/magento-2-empty-attribute-hide-in-product-details-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!