Magento 2 Add Custom Tab to Product Page

Magento 2 Add Custom Tab to Product Page

In this post we will show you Magento 2 Add Custom Tab to Product Page, hear for Magento 2 Add Custom Tab to Product Page we will give you demo and example for implement.

agento 2 Add Custom Tab to Product Page for including custom tabs. Gone is the local.xml document and the catalog.xml record. In it’s place, every module has it’s own particular arrangement of design records and layouts. In the present illustration, we will be adding a custom tab to the item see page. This tab will show diverse guarantee data in light of the estimation of the maker.

how to add Magento 2 Add Custom Tab to Product Page
how to add Magento 2 Add Custom Tab to Product Page

The initial step is to add the new tab to the catalog_product_view.xml record inside your subject envelope.

The envelope structure would be app/outline/frontend/ThemePackage/Theme/Magento_Catalog/format/catalog_product_view.xml.

We will include the tab by means of a refresh to the substance piece. That tab will call the warranty-info.phtml format.

The guarantee data layout, thusly will check the item’s maker esteem and show a static square particularly for that producer.

The guarantee info.phtml document will be in the app/plan/frontend/ThemePackage/Theme/Magento_Catalog/formats/item/see/folder.

The Custom Tabs download connect beneath will open a content record with all the design and layout pieces used to make this custom tab.

code for Magento 2 Add Custom Tab to Product Page

for Magento 2 Add Custom Tab to Product Page, in your theme’s Magento_Catalog/layout/catalog_product_view.xml file, add the following to the content block:

<referenceContainer name="content">
	<block class="Magento\Catalog\Block\Product\View\Description" name="product.info.details" template="product/view/details.phtml" after="product.info.media">
		<block class="Magento\Catalog\Block\Product\View\Description" name="product.info.description" template="product/view/attribute.phtml" group="detailed_info">
			<arguments>
				<argument name="at_call" xsi:type="string">getDescription</argument>
				<argument name="at_code" xsi:type="string">description</argument>
				<argument name="css_class" xsi:type="string">description</argument>
				<argument name="at_label" xsi:type="string">none</argument>
				<argument name="title" translate="true" xsi:type="string">Details</argument>
			</arguments>
		</block>
		<block class="Magento\Catalog\Block\Product\View\Attributes" name="product.attributes" as="additional" template="product/view/attributes.phtml" group="detailed_info">
			<arguments>
				<argument translate="true" name="title" xsi:type="string">More Information</argument>
			</arguments>
		</block>
		<block class="Magento\Catalog\Block\Product\View" name="warrantyinfo.tab" as="warrantyinfo" template="product/view/warranty_info.phtml" group="detailed_info" >
			<arguments>
			<argument translate="true" name="title" xsi:type="string">Warranty Information</argument>
			</arguments>
		</block>
	</block>
</referenceContainer>

for Magento 2 Add Custom Tab to Product Page, Template warranty_info.phtml contains::

<?php $_product = $block->getProduct(); ?>
	<?php if($_product->getResource()->getAttribute('manufacturer')->getFrontend()->getValue($_product)): ?>
	<?php if ($_product->getAttributeText('manufacturer') == 'Brand One'): ?>
		<?php echo $block->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('brand-one-warranty')->toHtml();?>
	<?php elseif ($_product->getAttributeText('manufacturer') == 'Brand Two'): ?>
		<?php echo $block->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('brand-two-warranty')->toHtml();?>
	<?php endif; ?>
<?php endif; ?>

Hope this code and post will helped you for implement Magento 2 Add Custom Tab to Product Page. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve onlincode. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs onlincode.org

Leave a Comment

Your email address will not be published. Required fields are marked *

8  +  1  =  

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US