H3XED

Magento CE How to Hide Empty Attributes From Additional Information on Product Page

Oct 28, 2015   Web Development   Nick Vogt   Comments
Please note that this post is over a year old and may contain outdated information.
If your Magento product pages are displaying the word "No" for attributes in the Additional Information page, and you'd prefer that empty attributes simply be hidden on product pages for products that don't have them filled out, here is a simple fix that only requires adding one line of code.

As always, you should use a custom package/theme and create edited versions of files, instead of editing default files themselves. But if you'd prefer to just edit the default files, at least make an original backup.

The file in question is this one:

app/design/frontend/base/default/template/catalog/product/view/attributes.phtml

You want to add this line to the foreach loop:

<?php if ($_data['value'] == 'No' || $_data['value'] === '') continue; ?>
Here it is in the file:

<tbody>
<?php foreach ($_additional as $_data): ?>
<?php if ($_data['value'] == 'No' || $_data['value'] === '') continue; ?>
    <tr>
        <th class="label"><?php echo $this->escapeHtml($this->__($_data['label'])) ?></th>
        <td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
    </tr>
<?php endforeach; ?>
</tbody>

Doing this will make Magento skip attributes that have a value of "No" or contain nothing at all. Unfortunately this does mean if you have products with attributes values of "No", those attributes will be skipped too.
Share This Post
Twitter
Learning Magento
Magento Beginner's Guide
Magento Beginner's Guide
See More Details
Magento SEO
Magento SEO
See More Details

Comments (0)

Share This Post
Twitter
Learning Magento
Magento Beginner's Guide
Magento Beginner's Guide
See More Details
Magento SEO
Magento SEO
See More Details
H3XED © Nick Vogt   RSS   Policies   Twitter