Hello Everyone,
In this blog, we will learn about how to add a Custom Tab in the Customer Account Section in Magento 2.
The customer account dashboard includes sections like My Account, My Wishlist, Addressbook, etc.
But sometimes requires to increase shopping experience for customers at that time this is useful.
Without wasting your time, let us guide you straight away. Follow the easy step given below to Add Custom Tab in Customer Account in Magento 2.
STEPS FOR ADD CUSTOM TAB IN CUSTOMER ACCOUNT IN MAGENTO 2
Step 1: Create customer_account.xml file
app/code/Vendor/Extension/view/frontend/layout/customer_account.xml
<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-navigation-custom">
<arguments>
<argument name="path" xsi:type="string">routename/customer/index</argument>
<argument name="label" xsi:type="string">Magecurious</argument>
</arguments>
</block>
</referenceBlock>
</body>
</page>
Step 2: Create routename_customer_index.xml file
app/code/Vendor/Extension/view/frontend/layout/routename_customer_index.xml
<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">Magecurious</argument>
</action>
</referenceBlock>
<referenceContainer name="content">
<block class="Magento\Framework\View\Element\Template" name="my_tab" template="Vendor_Module::mytab.phtml">
</block>
</referenceContainer>
</body>
</page>
Step 3: Create Index.php file
app/code/Vendor/Extension/Controller/Customer/Index.php
<?php
namespace Vendor\Extension\Controller\Customer;
class Index extends \Magento\Framework\App\Action\Action {
public function execute() {
$this->_view->loadLayout();
$this->_view->renderLayout();
}
}
?>
Step 4: Create mytab.phtml file
app/code/Vendor/Extension/view/frontend/templates/mytab.phtml
<?php
// Add Some Code Here for design
?>
<span> My Custom Tab.. </span>
Step 5: Finally run the below commands
$ php bin/magento cache:clean
$ php bin/magento cache:flush
Step 6: Output:
Now, go to My Account Section and you will see the output below.
Final Thoughts:
So this was the easiest way which we have told you in this blog. This is how you can Add Custom Tab in Customer Account in Magento 2. Hope you liked the blog.
So quickly go to the comment box and tell me how you like this blog?
Stay tuned with us on our site to get new updates of Magento.
Thanks for reading and visiting our site.
