Magento 2 in how to remove the frontend in products empty values?
-
07-02-2021 - |
Solution 2
<?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') {
}elseif($block->escapeHtml(__($_data['label']))=="Is Featured"){
}elseif($_data['value']=='No'){
}else{
?>
<tr>
<th class="col label" scope="row"><?= $block->escapeHtml(__($_data['label'])) ?></th>
<td class="col data yota-attribute-td" data-th="<?= $block->escapeHtml(__($_data['label'])) ?>"><?= /* @escapeNotVerified */ $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
</tr>
<?php
} ?>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php endif;?>
Its Working :)
OTHER TIPS
in
app/design/frontend/[theme_vendor]/[theme_name]/Magento_Catalog/templates/product/view/attributes.phtml
find this section in line 24 :
<?php foreach ($_additional as $_data): ?>
<tr>
<th class="col label" scope="row"><?= $block->escapeHtml(__($_data['label'])) ?></th>
<td class="col data yota-attribute-td" data-th="<?= $block->escapeHtml(__($_data['label'])) ?>"><?= /* @escapeNotVerified */ $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
</tr>
<?php endforeach; ?>
Just add
<?php if($_data['value'] == 'N/A') continue;?>
after
<?php foreach ($_additional as $_data): ?>
p.s If the mentioned file wasn't there you can create needed directories and copy attributes.phtml from magento core files:
vendor/magento/module-catalog/view/frontend/templates/product/view/attributes.phtml
or you can just edit the core file in magento (not recommended)
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange