问题
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