{"id":7272,"date":"2019-09-23T10:38:26","date_gmt":"2019-09-23T05:08:26","guid":{"rendered":"https:\/\/www.hiddentechies.com\/blog\/?p=7272"},"modified":"2019-09-27T13:39:05","modified_gmt":"2019-09-27T08:09:05","slug":"magento-2-add-custom-tab-customer-account","status":"publish","type":"post","link":"https:\/\/www.hiddentechies.com\/blog\/magento-2\/magento-2-add-custom-tab-customer-account\/","title":{"rendered":"Magento 2 &#8211; How to Add Custom Tab in Customer Account"},"content":{"rendered":"<p>In this post I am going to explain how to add custom tab in customer account in magento 2.<\/p>\n<p>In Magento 2, customer will be redirected to their account dashboard after login or signup. Customer My Account section contains various tabs such as My Account, My Orders, My Wishlist etc. Sometimes we need to add new custom tab to enhance customer shopping experience or to display some information.<\/p>\n<p>Follow the steps below to add custom tab in customer account section.<\/p>\n<p>Create customer_account.xml<\/p>\n<p>File Path: app\/code\/Ht\/Mymodule\/view\/frontend\/layout\/customer_account.xml<\/p>\n<pre class=\"lang:default decode:true \">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&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=\"customer_account_navigation\"&gt;\r\n            &lt;block class=\"Magento\\Framework\\View\\Element\\Html\\Link\\Current\" name=\"custom-tab-link\"&gt;\r\n                &lt;arguments&gt;\r\n                    &lt;argument name=\"path\" xsi:type=\"string\"&gt;mymodule\/customer\/index&lt;\/argument&gt;\r\n                    &lt;argument name=\"label\" xsi:type=\"string\"&gt;Ht Custom Tab&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>Create mymodule_customer_index.xml<\/p>\n<p>File Path: app\/code\/Ht\/Mymodule\/view\/frontend\/layout\/mymodule_customer_index.xml<\/p>\n<pre class=\"lang:default decode:true \">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\r\n\r\n&lt;page xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"..\/..\/..\/..\/..\/..\/..\/lib\/internal\/Magento\/Framework\/View\/Layout\/etc\/page_configuration.xsd\"&gt; \r\n    &lt;update handle=\"customer_account\"\/&gt; \r\n    &lt;body&gt; \r\n        &lt;referenceBlock name=\"page.main.title\"&gt; \r\n            &lt;action method=\"setPageTitle\"&gt; \r\n                &lt;argument translate=\"true\" name=\"title\" xsi:type=\"string\"&gt;Ht Custom Tab&lt;\/argument&gt; \r\n            &lt;\/action&gt; \r\n        &lt;\/referenceBlock&gt; \r\n        &lt;referenceContainer name=\"content\"&gt; \r\n            &lt;block class=\"Magento\\Framework\\View\\Element\\Template\" name=\"custom-tab\" template=\"Ht_Mymodule::customer\/account\/customtab.phtml\" \/&gt;\r\n        &lt;\/referenceContainer&gt; \r\n    &lt;\/body&gt; \r\n&lt;\/page&gt;<\/pre>\n<p>Create routes.xml<\/p>\n<p>File Path: app\/code\/Ht\/Mymodule\/etc\/frontend\/routes.xml<\/p>\n<pre class=\"lang:default decode:true \">&lt;?xml version=\"1.0\" ?&gt;\r\n\r\n&lt;config xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"urn:magento:framework:App\/etc\/routes.xsd\"&gt;\r\n    &lt;router id=\"standard\"&gt;\r\n        &lt;route frontName=\"mymodule\" id=\"mymodule\"&gt;\r\n            &lt;module name=\"Ht_Mymodule\"\/&gt;\r\n        &lt;\/route&gt;\r\n    &lt;\/router&gt;\r\n&lt;\/config&gt;<\/pre>\n<p>Create Index.php<\/p>\n<p>File Path: app\/code\/Ht\/Mymodule\/Controller\/Customer\/Index.php<\/p>\n<pre class=\"lang:default decode:true \">&lt;?php\r\n\r\nnamespace Ht\\Mymodule\\Controller\\Customer;\r\n\r\nclass Index extends \\Magento\\Framework\\App\\Action\\Action \r\n{\r\n    public function execute() \r\n    {\r\n        $this-&gt;_view-&gt;loadLayout();\r\n        $this-&gt;_view-&gt;renderLayout();\r\n    }\r\n}<\/pre>\n<p>Create customtab.phtml<\/p>\n<p>File Path: app\/code\/Ht\/Mymodule\/view\/frontend\/templates\/customer\/account\/customtab.phtml<\/p>\n<pre class=\"lang:default decode:true \">&lt;?php \r\n\r\n\/\/ Add your tab content here.\r\necho \"Ht custom tab content goes here\";<\/pre>\n<p>Thats it. Enjoy Magento 2!!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post I am going to explain how to add custom tab in customer account in magento 2. In Magento 2, customer will be redirected to their account dashboard after login or signup. Customer My Account section contains various tabs such as My Account, My Orders, My Wishlist etc. Sometimes we need to add&#8230; <\/p>\n<div class=\"actions\"><a href=\"https:\/\/www.hiddentechies.com\/blog\/magento-2\/magento-2-add-custom-tab-customer-account\/\">Continue Reading<\/a><\/div>\n","protected":false},"author":1,"featured_media":7336,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[59],"tags":[687,10,27],"_links":{"self":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts\/7272"}],"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=7272"}],"version-history":[{"count":1,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts\/7272\/revisions"}],"predecessor-version":[{"id":7273,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts\/7272\/revisions\/7273"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/media\/7336"}],"wp:attachment":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/media?parent=7272"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/categories?post=7272"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/tags?post=7272"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}