{"id":7404,"date":"2019-10-04T12:42:33","date_gmt":"2019-10-04T07:12:33","guid":{"rendered":"https:\/\/www.hiddentechies.com\/blog\/?p=7404"},"modified":"2019-10-04T15:26:38","modified_gmt":"2019-10-04T09:56:38","slug":"magento-2-add-custom-tab-on-product-view-page","status":"publish","type":"post","link":"https:\/\/www.hiddentechies.com\/blog\/magento-2\/magento-2-add-custom-tab-on-product-view-page\/","title":{"rendered":"Magento 2 &#8211; How to Add Custom Tab on Product View Page"},"content":{"rendered":"<p>In this post I am going to explain how to add custom tab on product detail page in Magento 2.<\/p>\n<p>Here, I am using my custom module \u2013 Ht_Mymodule<\/p>\n<p>First, create product page layout file catalog_product_view.xml and add following code in it.<\/p>\n<p>File Path: app\/code\/Ht\/Mymodule\/view\/frontend\/layout\/catalog_product_view.xml<\/p>\n<pre class=\"lang:default decode:true \">&lt;?xml version=\"1.0\"?&gt;\r\n\r\n&lt;page xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"urn:magento:framework:View\/Layout\/etc\/page_configuration.xsd\"&gt;\r\n    &lt;body&gt;\r\n        &lt;referenceBlock name=\"product.info.details\"&gt;\r\n            &lt;block class=\"Magento\\Catalog\\Block\\Product\\View\" name=\"custom.tab\" template=\"Ht_Mymodule::product\/view\/custom-tab.phtml\" group=\"detailed_info\" &gt;\r\n                &lt;arguments&gt;\r\n                    &lt;argument name=\"title\" translate=\"true\" xsi:type=\"string\"&gt;Custom Tab&lt;\/argument&gt;\r\n                    &lt;argument name=\"css_class\" xsi:type=\"string\"&gt;custom-tab&lt;\/argument&gt;\r\n                    &lt;argument name=\"sort_order\" xsi:type=\"string\"&gt;100&lt;\/argument&gt;\r\n                &lt;\/arguments&gt;\r\n            &lt;\/block&gt;\r\n        &lt;\/referenceBlock&gt;\r\n    &lt;\/body&gt;\r\n&lt;\/page&gt;<\/pre>\n<p>Next to that, create the template file custom-tab.phtml and write your content in that.<\/p>\n<p>File Path: app\/code\/Ht\/Mymodule\/view\/frontend\/templates\/product\/view\/custom-tab.phtml<\/p>\n<p>Now clear the cache and check for the result.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7405\" src=\"https:\/\/www.hiddentechies.com\/blog\/wp-content\/uploads\/2019\/10\/product-custom-tab.png\" alt=\"Magento 2 - How to Add Custom Tab on Product View Page\" width=\"945\" height=\"349\" srcset=\"https:\/\/www.hiddentechies.com\/blog\/wp-content\/uploads\/2019\/10\/product-custom-tab.png 945w, https:\/\/www.hiddentechies.com\/blog\/wp-content\/uploads\/2019\/10\/product-custom-tab-300x111.png 300w, https:\/\/www.hiddentechies.com\/blog\/wp-content\/uploads\/2019\/10\/product-custom-tab-768x284.png 768w, https:\/\/www.hiddentechies.com\/blog\/wp-content\/uploads\/2019\/10\/product-custom-tab-800x295.png 800w\" sizes=\"(max-width: 945px) 100vw, 945px\" \/><\/p>\n<p>If you want to display product details in this file then you can simply get product data by:<\/p>\n<pre class=\"lang:default decode:true \">$_product = $block-&gt;getProduct();\r\n\r\n$productId = $_product-&gt;getId();\r\n$productName = $_product-&gt;getName();<\/pre>\n<p>Thats it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post I am going to explain how to add custom tab on product detail page in Magento 2. Here, I am using my custom module \u2013 Ht_Mymodule First, create product page layout file catalog_product_view.xml and add following code in it. File Path: app\/code\/Ht\/Mymodule\/view\/frontend\/layout\/catalog_product_view.xml &lt;?xml version=&#8221;1.0&#8243;?&gt; &lt;page xmlns:xsi=&#8221;http:\/\/www.w3.org\/2001\/XMLSchema-instance&#8221; xsi:noNamespaceSchemaLocation=&#8221;urn:magento:framework:View\/Layout\/etc\/page_configuration.xsd&#8221;&gt; &lt;body&gt; &lt;referenceBlock name=&#8221;product.info.details&#8221;&gt; &lt;block class=&#8221;Magento\\Catalog\\Block\\Product\\View&#8221;&#8230; <\/p>\n<div class=\"actions\"><a href=\"https:\/\/www.hiddentechies.com\/blog\/magento-2\/magento-2-add-custom-tab-on-product-view-page\/\">Continue Reading<\/a><\/div>\n","protected":false},"author":1,"featured_media":7407,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[59],"tags":[10],"_links":{"self":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts\/7404"}],"collection":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/comments?post=7404"}],"version-history":[{"count":1,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts\/7404\/revisions"}],"predecessor-version":[{"id":7406,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts\/7404\/revisions\/7406"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/media\/7407"}],"wp:attachment":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/media?parent=7404"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/categories?post=7404"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/tags?post=7404"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}