Skip to main content
MagentoTipsWeb Development

Hide empty attributes in Magento

By 6 August 2014No Comments

On a product page Magento will show some attributes on the front-end as “No” or “N/A” when that attribute is empty, not very useful for the majority of store owners who may not have their attribute sets tightly defined. To fix this you can move the attributes.phtml file into your theme and edit the foreach loop as below;

<?php foreach ($_additional as $_data): ?>
    <?php $_attribute = $_product->getResource()->getAttribute($_data['code']);?>
    <?php if (!is_null($_product->getData($_attribute->getAttributeCode())) && ((string)$_attribute->getFrontend()->getValue($_product) != '')): ?>
        <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>
    <?php endif;?>
<?php endforeach; ?>

The file should be located at app/design/frontend/default/[Your Theme]/template/catalog/product/view/attributes.phtml

Close Menu
Portanor House
Manor Court, Manor Royal
Crawley
RH10 9PY

T: +44 (0)330 056 4072
E: [email protected]