Sometimes we come across a store that wants to have many different product attributes, but they only want the default attribute set. This means that every product will have lets say 10+ options that sometimes don’t apply to certain products. For instance a piece of clothing might need a size attribute, but a piece of furniture doesn’t. Because the store uses the same attribute sets for each products the empty size attribute will show up like this:
This is ofcourse very confusing for customers, so the better option would be to hide attribute value’s that are empty. This can be done with a small piece of code. Find and open the attributes.phtml
file. This file can be found here:app/design/frontend/default/[theme name]/template/catalog/product/view/attribute.phtml
Open the file and search for the following lines:
<?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; ?>
Replace the entire foreach loop with the following lines of code:
<?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! Empty attributes will now be hidden from your product pages. Don’t forget to refresh your cache to see the changes.
SOurce: https://tejabhagavan.blogspot.in/2016/03/hide-magento-attributes-with-no-value-2.html