<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> <module name="[VendorName]_[ModuleName]" setup_version="1.0.0"> <sequence> <module name="Magento_Catalog"name="Magento_Review"/> </sequence> </module> </config> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> <module name="[VendorName]_[ModuleName]" setup_version="1.0.0"> <sequence> <module name="Magento_Catalog"/> </sequence> </module> </config> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> <module name="[VendorName]_[ModuleName]" setup_version="1.0.0"> <sequence> <module name="Magento_Review"/> </sequence> </module> </config> 1. Create new product attribute. Admin Menu > Stores > Attributes > Product > Add New Attribute [Text Field] = (i.e. CustomSize Tabchart) 2. Assign attribute to attribute set. 3. Update Code From: <?php $attributeCode = '<your_custom_attribute_name>'; ?> To: <?php $attributeCode = 'custom_tab';'sizechart'; ?> 4. SetIn attributeadmin valueproduct inadd product.text to "sizechart" attribute Catalog > Products > Edit > CustomSize Tabchart = (i.e. warrantylevi-size) 5. Create CMS Block Admin Menu > Content > Elements > Blocks > Add New Block = Same identifier which you have added value in product's "Custom"Size Tab"chart" attribute textbox (i.e. warrantylevi-size) For dropdown or multiselect attribute, you need to change code accordingly or add multiple conditions for the same.
1. Create new product attribute. Admin Menu > Stores > Attributes > Product > Add New Attribute [Text Field] = (i.e. Custom Tab) 2. Assign attribute to attribute set. 3. Update Code From: <?php $attributeCode = '<your_custom_attribute_name>'; ?> To: <?php $attributeCode = 'custom_tab'; ?> 4. Set attribute value in product. Catalog > Products > Edit > Custom Tab = (i.e. warranty) 5. Create CMS Block Admin Menu > Content > Elements > Blocks > Add New Block = Same identifier which you have added value in product's "Custom Tab" attribute textbox (i.e. warranty) 1. Create new product attribute. Admin Menu > Stores > Attributes > Product > Add New Attribute [Text Field] = (i.e. Size chart) 2. Assign attribute to attribute set. 3. Update Code From: <?php $attributeCode = '<your_custom_attribute_name>'; ?> To: <?php $attributeCode = 'sizechart'; ?> 4. In admin product add text to "sizechart" attribute Catalog > Products > Edit > Size chart = (i.e. levi-size) 5. Create CMS Block Admin Menu > Content > Elements > Blocks > Add New Block = Same identifier which you have added value in product's "Size chart" attribute textbox (i.e. levi-size) For dropdown or multiselect attribute, you need to change code accordingly or add multiple conditions for the same.
You can try code, same as below:
- app/code/[VendorName]/[ModuleName]/registration.php
\Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, '[VendorName]_[ModuleName]', __DIR__ );
- app/code/[VendorName]/[ModuleName]/etc/module.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> <module name="[VendorName]_[ModuleName]" 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 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="[VendorName]_[ModuleName]::product/view/details/custom_tab.phtml" group="detailed_info"> <arguments> <argument translate="true" name="title" xsi:type="string">Tab Title</argument> </arguments> </block> </referenceBlock> </body> </page>
- app/code/[VendorName]/[ModuleName]/view/frontend/templates/product/view/details/custom_tab.phtml
<?php $attributeCode = '<your_custom_attribute_name>'; ?> <?php $blockIdentifier = $block->getProduct()->getData($attributeCode); ?> <?php if($blockIdentifier): ?> <?php echo $block->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId($blockIdentifier)->toHtml(); ?> <?php endif; ?> Note:
1. Create new product attribute. Admin Menu > Stores > Attributes > Product > Add New Attribute [Text Field] = (i.e. Custom Tab) 2. Assign attribute to attribute set. 3. Update Code From: <?php $attributeCode = '<your_custom_attribute_name>'; ?> To: <?php $attributeCode = 'custom_tab'; ?> 4. Set attribute value in product. Catalog > Products > Edit > Custom Tab = (i.e. warranty) 5. Create CMS Block Admin Menu > Content > Elements > Blocks > Add New Block = Same identifier which you have added value in product's "Custom Tab" attribute textbox (i.e. warranty) default