How to Hide Magento Attributes with No Value

attributesmagento-1.9product-attributeproducts

I have a set of Attributes showing up in my additional tabs section of my product page, the attributes are populated via the backend and show up on the front. Some attributes based on the product have empty fields and show up as N/A i want these fields to be just blank so it looks like the field is empty rather than Not Applicable or has No written in it.

example on what the products look like with N/A populated fields:

enter image description here

I read up on some posts and questions from people who have a smiliar problem and the fix would involve me going to.

/app/design/frontend/[theme name]/[package name]/template/catalog/product/view/attribute.phtml

and implementing the following 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 } ?>

This doesnt work as i dont have the attribute.phtml file located in that section of my folder structure. See below for an example:

enter image description here


Edit: To further explain after finding the attribute.phtml file i copy in the code and now i get an empty blank page where the attributes should come up and everything below the attributes list dissapears too including the footer.

Everything above the attributes stay such as the product iamge, description header and menu.

Edit2: I found the solution by using a different code the outcome is not exactly how i wanted it by just removing the words N/A and No and keeping the actual attribute label there but instead it removes the full row

Open the file and search for the 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 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; ?>

Source: http://codingbasics.net/hide-magento-attributes-value/

Source: http://www.magthemes.com/magento-blog/empty-attributes-showing-na-fix/

Best Answer

You can copy attributes.phtml file from Magento base theme app/design/frontend/base/default/template/catalog/product/view to your current theme /app/design/frontend/[theme name]/[package name]/template/catalog/product/view.

and then update the file to exclude empty attributes.