15 Aug, 2021
Today we going to create a new custom product tab in Magento 2.x
Product tab is usefull to showing product details with specific categorised. We will going to create new product tab in magento 2.x. Magento 2 provide 3 to 4 product tabs, We will add our custom product tab in Magento 2. It's very simple to add our custom product tab in Magento 2.
Let's start by creating a new custom product tab.
<?php
//file path: MAGENTO_ROOT/app/code/RS/ProductTab/registration.php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
"RS_ProductTab",
__DIR__
);
<?xml version="1.0"?>
<!-- file path: MAGENTO_ROOT/app/code/RS/ProductTab/etx/module.xml -->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="RS_ProductTab" setup_version="1.0.0" />
</config>
<?xml version="1.0"?>
<!-- file path: MAGENTO_ROOT/app/code/RS/ProductTab/view/frontend/layout/catalog_product_view.xml -->
<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="rs.product.tab" template="RS_ProductTab::catalog/product/view/custom-tab.phtml" group="detailed_info" >
<arguments>
<argument translate="true" name="title" xsi:type="string">Custom Tab</argument>
</arguments>
</block>
</referenceBlock>
</body>
</page>
<?php
/* file path: MAGENTO_ROOT/app/code/RS/ProductTab/view/frontend/templates/catalog/product/view/custom-tab.phtml */
?>
<h3><?= __("Custom product tab") ?></h2>
<p><?php /* YOUR BODY CONTENT */ ?></p>
php bin/magento module:enable RS_ProductTab
php bin/magento setup:di:compile
php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy
That's the steps to create a custom product tab in Magento 2.x
RAJU SADADIYA (MAGENTO DEVELOPER)