I created a custom product tab that I want to use for a specific attribute set. For that attribute set I have created a number of specific attributes.

The custom product tab works nice. However it is visible for every product, which is not wanted. How could I make sure that the tab is only visible for a specific attribute set (or product attributes for that matter).

My code:

  1. app/code/[VendorName]/[ModuleName]/registration.php

  2. app/code/[VendorName]/[ModuleName]/etc/module.xml

    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
        <module name="Mark_Eopyy" setup_version="1.0.0">
            <module name="Magento_Catalog"/>
  3. app/code/[VendorName]/[ModuleName]/view/frontend/layout/catalog_product_view.xml

    <?xml version="1.0"?>
    <page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
            <referenceBlock name="product.info.details">         
               <block class="Magento\Catalog\Block\Product\View" name="custom.tab" template="Mark_Eopyy::custom_tab.phtml" group="detailed_info">
                        <argument translate="true" name="title" xsi:type="string">ΕΟΠΥΥ</argument>
  4. app/code/[VendorName]/[ModuleName]/view/frontend/templates/product/view/details/custom_tab.phtml

    $product = $block->getProduct();
    <h1 style="color: #1979c3"><?php echo $product->getData('product_attribute'); ?></h1>

Thank you


I found a solution by wrapping the html part of the template file in a PHP if statement.


$product = $block->getProduct();
<?php if( $product->getData('product_attribute') ): ?>
<h1 style="color: #1979c3"><?php echo $product->getData('product_attribute'); ?></h1>

<?php endif; ?>

However I don't tick this as solved yet, in case someone points to a more elegant solution.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.