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:
app/code/[VendorName]/[ModuleName]/registration.php
<?php \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, 'Mark_Eopyy', __DIR__ );
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"> <sequence> <module name="Magento_Catalog"/> </sequence> </module> </config>
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"> <body> <referenceBlock name="product.info.details"> <block class="Magento\Catalog\Block\Product\View" name="custom.tab" template="Mark_Eopyy::custom_tab.phtml" group="detailed_info"> <arguments> <argument translate="true" name="title" xsi:type="string">ΕΟΠΥΥ</argument> </arguments> </block> </referenceBlock> </body> </page>
app/code/[VendorName]/[ModuleName]/view/frontend/templates/product/view/details/custom_tab.phtml
<?php $product = $block->getProduct(); ?> <h1 style="color: #1979c3"><?php echo $product->getData('product_attribute'); ?></h1>
Thank you