
Magento 2.x – How to remove empty attributes “N/A” on PDP tabs
If you don’t want to show to the customer the empty attributes of your products in the PDP, for example in the More Information tab, such like this:
You will need to do the following:
- Override the file vendor/magento/module-catalog/view/frontend/templates/product/view/attributes.phtml into your theme:
1 |
app/design/frontend/{Packagename}/{themename}/Magento_Catalog/templates/product/view/attributes.phtml |
or
1 |
app/code/{Packagename}/{themename}/Magento_Catalog/templates/product/view/attributes.phtml |
- Edit your theme new file, adding the following code:
1<?php if($_data['value'] == 'N/A') continue;?>
just below this:
1<?php foreach ($_additional as $_data): ?> - So, this should be the full code of your phtml:
12345678910111213141516171819202122232425262728293031323334<?php/*** Copyright © 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"><?= /* @escapeNotVerified */ __('More Information') ?></caption><tbody><?php foreach ($_additional as $_data): ?><?php if($_data['value'] == 'N/A') 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;?> - Clean the following folders:
123rm var/cacherm view_preprocessedrm pub/static/frontend
Or just clean cache and make an static content deploy instead. - Try again, and you should get the following result: