Add Custom Tab On Product View Page – Magento2

Here we will see how to add new custom tab on product view page in magento2.
First create file ‘catalog_product_view.xml’ in location ‘Vendor/Test/view/frontend/layout’:

<?xml version=”1.0″?>
<page layout=”2columns-left” xmlns:xsi=”” xsi:noNamespaceSchemaLocation=”urn:magento:framework:View/Layout/etc/page_configuration.xsd”>
<referenceBlock name=””>
<block class=”Magento\Catalog\Block\Product\View” name=”” template=”Vendor_Test::webe_tab.phtml” group=”detailed_info” >
<argument translate=”true” name=”title” xsi:type=”string”>Webetutiorial Tab</argument>

Now create file ‘webe_tab.phtml’ in location ‘Vendor/Test/view/frontend/templates’ and write content on the file.

If you want to use product details on this file, you can simply get product by $product = $block->getProduct();

// get current product
$product = $block->getProduct();
echo $product->getName();

Leave a Reply