0

I am using Magento 2.3

I have created 4 separate tabs in the product details page. see below code:

app/design/frontend/myvendor/theme/Magento_Catalog/layout/catalog_product_view.xml

<block class="Magento\Catalog\Block\Product\View\Description" name="product.info.details" template="Magento_Catalog::product/view/details.phtml" after="product.info.media">
  <block class="Magento\Catalog\Block\Product\View\Description" name="product.info.description" as="description" template="Magento_Catalog::product/view/description.phtml" group="detailed_info">
      <arguments>
          <argument name="at_call" xsi:type="string">getDescription</argument>
          <argument name="at_code" xsi:type="string">description</argument>
          <argument name="css_class" xsi:type="string">description</argument>
          <argument name="at_label" xsi:type="string">none</argument>
      </arguments>
  </block>
</block>



<block class="Magento\Catalog\Block\Product\View" name="product.info.details.models" template="Magento_Catalog::product/view/details.phtml">
  <block class="Magento\Catalog\Block\Product\View\Attributes" name="product.attributes" as="additional" template="Magento_Catalog::product/view/attributes.phtml" group="detailed_info">
      <arguments>
          <argument translate="true" name="title" xsi:type="string">Product Tab 2</argument>
      </arguments>
  </block>
</block>


<block class="Magento\Catalog\Block\Product\View" name="product.info.details.more" template="Magento_Catalog::product/view/details.phtml">
    <block class="Magento\Catalog\Block\Product\View\Attributes" name="more.product.info" as="information" template="Magento_Catalog::product/view/more_info.phtml" group="detailed_info" before="reviews.tab">
        <arguments>
            <argument name="title" translate="true" xsi:type="string">More Information</argument>
        </arguments>
    </block>
</block>

<block class="Magento\Review\Block\Product\Review" name="reviews.tab" as="reviews" template="Magento_Review::review.phtml" group="detailed_info">
    <block class="Magento\Review\Block\Form" name="product.review.form" as="review_form">
        <container name="product.review.form.fields.before" as="form_fields_before" label="Review Form Fields Before"/>
    </block>
</block>

app/design/frontend/myvendor/theme/Magento_Catalog/templates/product/view/details.phtml

<?php


// @codingStandardsIgnoreFile

?>
<?php 
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $product = $objectManager->get('Magento\Framework\Registry')->registry('current_product');
    $description = $product->getResource()->getAttribute('description')->getFrontend()->getValue($product);
?>

<?php if ($detailedInfoGroup = $block->getGroupChildNames('detailed_info', 'getChildHtml')):?>
    <div class="product info detailed">

        <?php $layout = $block->getLayout(); ?>
        <div class="product data items" data-mage-init='{"tabs":{"openedState":"active"}}'>
            <?php foreach ($detailedInfoGroup as $name):?>
                <?php
                    $html = $layout->renderElement($name);
                    if (!trim($html)) {
                        continue;
                    }
                    $alias = $layout->getElementAlias($name);
                    $label = $block->getChildData($alias, 'title');
                ?>
                    <div class="data item content" id="<?= /* @escapeNotVerified */ $alias ?>" data-role="content">
                    <?= /* @escapeNotVerified */ $html ?>
                </div>
            <?php endforeach;?>
        </div>
    </div>
<?php endif; ?>

app/design/frontend/myvendor/theme/Magento_Catalog/templates/product/view/more_info.phtml

<?php
    $_helper = $this->helper('Magento\Catalog\Helper\Output');
    $_product = $block->getProduct();
?>

<?php if ($_additional = $block->getAdditionalData()): ?>
    <div class="additional-attributes-wrapper table-wrapper">
    <h3>MoreInformation</h3>
        <table class="data table additional-attributes" id="product-attribute-specs-table">
            <tbody>
                <?php foreach ($_additional as $_data): ?>
                    <?php
                    //$label = $_data['label']; 
                    if($_data['label'] != "Description"){ ?>
                    <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 } ?>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>

<?php endif; ?>

I have displayed additional attributes in the "More Information" tab. when I have set "Visible on Catalog Pages on Storefront" to NO for all additional attributes then all attributes are removed from the tab but the tab is still displaying on the front end.

So I want to remove the "More information" tab completely when "Visible on Catalog Pages on Storefront" to NO for all additional attributes.

How can I do this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.