Hello Magento Folks,
In this article, I will illustrate How to add Custom Tab in Customer Account in Magento 2. Also, check out our previously published blog where I have discussed 7 Proven Steps to Speed up Your Magento 2 Store.
Basically, by default, Magento 2 provides settings where the store customers will automatically redirect to the customer account dashboard after the registration or login process. Mainly the customer account dashboard includes My Account, My Orders, My Wishlist sections.
Despite that, in many situations to increase the user experience during shopping from your store all the online store owners prefer to provide addon tabs for the customers to the dashboard for reviewing their processing refunds, query ticket, or many such types of custom requirements. Unfortunately, by default, Magento 2 does not provide such add-on features. Hence to fulfill this requirement the admin needs to add Custom Tab in the Customer Account in Magento 2. Check out the below steps to add a custom tab in customer’s accounts.
Step 1: Firstly, we will need to Create Customer Account Layout
For this create a file namely customer_account.xml in the below-given path and add the following code respectively.
app\code\Vendor\Extension\view\frontend\layout\
<?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body> <referenceBlock name="customer_account_navigation"> <block class="Magento\Framework\View\Element\Html\Link\Current" name="customer-account-custom-tab"> <arguments> <argument name="path" xsi:type="string">routesname/customer/index</argument> <argument name="label" xsi:type="string">Custom Tab Name Here</argument> </arguments> </block> </referenceBlock> </body> </page>
Step 2: Create routes.xml in the below-given path and add the following code respectively.
app\code\Vendor\Extension\etc\frontend\
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd"> <router id="standard"> <route frontName="routesname" id="routesname"> <module name="Vendor_Extension"/> </route> </router> </config>
Step 3: Now navigate to the following path and create the routesname_customer_index.xml file and add the below-given code to it.
app\code\Vendor\Extension\view\frontend\layout\
<?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd"> <update handle="customer_account"/> <body> <referenceBlock name="page.main.title"> <action method="setPageTitle"> <argument translate="true" name="title" xsi:type="string">Custom Tab Title Here</argument> </action> </referenceBlock> <referenceContainer name="content"> <block class="Magento\Framework\View\Element\Template" name="custom_tab" template="Vendor_Extension::customtab.phtml" /> </referenceContainer> </body> </page>
Step 4: Create a file namely the Index.php file in the below-given path and add the following code respectively.
app\code\Vendor\Extension\Controller\Customer\
<?php namespace Vendor\Extension\Controller\Customer; class Index extends \Magento\Framework\App\Action\Action { public function execute() { $this->_view->loadLayout(); $this->_view->renderLayout(); } }
Step 5: At last, create customtab.phtml file as given below path add code.
app\code\Vendor\Extension\view\frontend\templates
<?php echo __("Here is your Tab Content."); ?>
Output:
That’s It, You are done with adding Custom Tab in Customer Account in Magento 2.
Most probably all are able to follow the above illustration step by step and successfully added the Custom Tab in Customer Account in your Magento 2 store. If you need any help then you can reach our certified developers for precisely adding the Custom Tab in Customer Account in your Magento 2 store.
Comment down your views or difficulties if any in the comment section below.
Share the article with your Magento Developer Friends.
Happy Reading.
In modern web development, seamless navigation and state management are crucial for delivering a smooth…
Magento Open Source 2.4.8 beta version released on October 8, 2024. The latest release of…
Hello Magento Friends, Creating catalog price rules programmatically in Magento 2 can be a valuable…
As the world of eCommerce continues to thrive, Shopify has become one of the most…
Shopify Remix is an innovative framework that provides a streamlined experience for building fast, dynamic,…
Building a successful eCommerce store requires expertise, and for many businesses, Shopify has become the…
View Comments
Hi Dhiren,
Your article is helpful for me!
By the way, how to add ACL for the new created custom tab?
Many thanks!
James
By default Customer Account section shows to login customers only, still, you can apply ACL using the controller