cancel
Showing results for 
Search instead for 
Did you mean: 

How to remove empty attributes “N/A” in Magento 2?

SOLVED

How to remove empty attributes “N/A” in Magento 2?

I am using Magento 2.1.7 with Porto theme, I recently updated theme and magento now in product information I am also seeing empty attributes that are unrelated to the current products as N/A . how can I hide them?

I saw people discussing here this in Magento 1. but it doesn't work for 2.0.

please help if you know how to do it. thanks


Magento ver. 2.1.7
Theme: Porto 2.5.0

9 REPLIES

Re: How to remove empty attributes “N/A” in Magento 2?

Just override file into your theme,

app/code/{Packagename}/{themename}/Magento_Catalog/templates/product/view/attributes.phtml

Just keep line, <?php if($_data['value'] == 'N/A') continue;?> after <?php foreach ($_additional as $_data): ?> line,

 

Full code,

<?php
/**
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

/**
 * Product additional attributes template
 *
 * @var $block \Magento\Catalog\Block\Product\View\Attributes
 */
?>
<?php
    $_helper = $this->helper('Magento\Catalog\Helper\Output');
    $_product = $block->getProduct()
?>
<?php if ($_additional = $block->getAdditionalData()): ?>
    <div class="additional-attributes-wrapper table-wrapper">
        <table class="data table additional-attributes" id="product-attribute-specs-table">
            <caption class="table-caption"><?php /* @escapeNotVerified */ echo __('More Information') ?></caption>
            <tbody>
            <?php foreach ($_additional as $_data): ?>
                <?php if($_data['value'] == 'N/A') continue;?>
                <tr>
                    <th class="col label" scope="row"><?php echo $block->escapeHtml(__($_data['label'])) ?></th>
                    <td class="col data" data-th="<?php echo $block->escapeHtml(__($_data['label'])) ?>"><?php /* @escapeNotVerified */ echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
    </div>
<?php endif;?>

Clear cache.

If Issue solved, click Kudos and Accept as Solution.

If Issue Solved, Click Kudos/Accept As solutions.

Re: How to remove empty attributes “N/A” in Magento 2?

wow man you relived me from a disaster. it worked. thanks a lot! Smiley Very HappyHeart

Re: How to remove empty attributes “N/A” in Magento 2?

Not working for me 2.1.8 with custom theme with Blank as base. Can you please help ?

Re: How to remove empty attributes “N/A” in Magento 2?

I changed N/A to 'Nee' then it is wroking on the Dutch site, but not in the English or German. What is value I have to put in to get it working for all languages ?

Re: How to remove empty attributes “N/A” in Magento 2?

The files is in 2.1.8 located somewhere else:

vendor/magento/module-catalog/view/frontend/templates/product/view

 

I translate Nee to N/A with inline translation, problem solved.

Re: How to remove empty attributes “N/A” in Magento 2?

Is this the same in version 1.9.3.4 also? If not what do I need to do?

Re: How to remove empty attributes “N/A” in Magento 2?

Awesome. Was looking for that. In regards to different languages:

If you use

<?php if($_data['value'] == __('N/A')) continue;?>

instead, it works language-independent, as well!

Re: How to remove empty attributes “N/A” in Magento 2?

To support multiple languages, you may replace:

<?php if($_data['value'] == 'N/A') continue;?>

with:

<?php if(is_object($_data['value'])) continue; ?>

 

Re: How to remove empty attributes “N/A” in Magento 2?

Update: I found out that this fix is not working on configurable products like it does on simples, so this is my current attributes.phtml after I fixed it (if it helps someone...):

<?php
    $_helper = $this->helper('Magento\Catalog\Helper\Output');
    $_product = $block->getProduct();
$excludeAttr = []; $_additionalData = []; $attributes = $_product->getAttributes(); foreach ($attributes as $attribute) { if ($attribute->getIsVisibleOnFront() && !in_array($attribute->getAttributeCode(), $excludeAttr)) { $value = $attribute->getFrontend()->getValue($_product); if ($attribute->getFrontendInput() == 'price' && is_string($value)) { $value = $this->priceCurrency->convertAndFormat($value); } if (is_string($value) && strlen($value)) { $_additionalData[$attribute->getAttributeCode()] = [ 'label' => __($attribute->getStoreLabel()), 'value' => $value, 'code' => $attribute->getAttributeCode(), ]; } } } ?> <?php if ($_additionalData): ?> <div class="additional-attributes-wrapper table-wrapper"> <table class="data table additional-attributes" id="product-attribute-specs-table"> <caption class="table-caption"><?= /* @escapeNotVerified */ __('More Information') ?></caption> <tbody> <?php foreach ($_additionalData as $_data): ?> <?php if(is_object($_data['value'])) continue; ?> <tr> <th class="col label" scope="row"><?= $block->escapeHtml(__($_data['label'])) ?></th> <td class="col data" data-th="<?= $block->escapeHtml(__($_data['label'])) ?>"><?= /* @escapeNotVerified */ $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td> </tr> <?php endforeach; ?> </tbody> </table> </div> <?php endif;?>