magento 2空属性隐藏在产品详细信息页面中 [英] magento 2 empty attribute hide in product details page
问题描述
Magento 2专家, 您能帮我一下,在magento 2产品详细信息页面中隐藏空/NA属性吗?
Magento 2 experts, Can you please help me, to hide empty/NA attribute in magento 2 products details page ?
非常感谢
推荐答案
Well, This is magento core issue: https://github.com/magento/magento2/issues/9961 , But you can use following solution for now.
从以下位置访问attributes.phtml文件:/vendor/magento/module-catalog/view/frontend/templates/product/view/attributes.phtml
Get to attributes.phtml file from :/vendor/magento/module-catalog/view/frontend/templates/product/view/attributes.phtml
复制此文件并粘贴到您的主题中:/app/design/frontend/[您的软件包]/[您的主题]/template/catalog/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.
搜索以下代码:
<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>
上述解决方案在Magento 2.2中运行完美
Above solution is working perfectly in Magento 2.2
这篇关于magento 2空属性隐藏在产品详细信息页面中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!