Skip to content

Instantly share code, notes, and snippets.

@yogeshdubey2006
Created July 18, 2019 12:36
Show Gist options
  • Save yogeshdubey2006/0025a68500485fef0e6b10ebc3b41981 to your computer and use it in GitHub Desktop.
Save yogeshdubey2006/0025a68500485fef0e6b10ebc3b41981 to your computer and use it in GitHub Desktop.
Magento 2 - remove empty attributes "N/A" and "No"
<?php
# Path: \app\design\frontend\packageName\themeName\Magento_Catalog\templates\product\view\attributes.phtml
/**
* 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'] == 'No' || $_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;?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment