How To Hide Empty Attribute In Magento?

On product detail page when Magento finds some attribute as an empty field, it shows “No” or “N/A”. You can hide those empty attributes by just edit your template file named as “attributes.phtml”. Just be sure that you are editing your own theme template file, better you use system “Template Path Hints”.

In my case it was /app/design/frontend/default/default/template/easytabs as I was using an extension. Default is /app/design/frontend/default/YOUR THEME/template/catalog/product/view/attribute.phtml. Now edit attribute.phtml file:

Find following lines:

<?php foreach ($_additional as $_data): ?>
    <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 endforeach; ?>

Replace these lines with this:

<?php foreach ($_additional as $_data): ?>
	<?php if ((string)$_data['value'] != '' and $_data['value'] != 'N/A'): ?>
		<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; ?>

OR

<?php foreach ($_additional as $_data): ?>
    <?php $_attribute = $_product->getResource()->getAttribute($_data['code']);
    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 } ?>
<?php endforeach; ?>

Thats it. Thanks to Hudony for easy solution.

  • Sparc

    This doesn’t work for me, I’m using 1.7
    Is anybody having success?

    • Roshan Lal

      Are you getting some error?

  • Kurt Hansen

    Thanks, worked nicely on 1.7.0.2 !

  • AJ

    How would you edit this with the compare/list.phtml page?

  • soni

    /app/design/frontend/default/YOUR THEME/template/catalog/product/view/attribute.phtml Use this path

  • David Line

    This works for me as well. Thanks!

  • hudony

    I came up with this :

    • hudony

      if ((string)$_data['value'] != ” and $_data['value'] != ‘N/A’):

      • http://www.roshanlal.in roshan lal

        Hi Hudony,

        Thanks for sharing this.

        regards,
        Roshan

  • sidlo

    second solution works first doesn’t. Thank you :)