Merchants may want to view some additional information like comments , reward points etc of a particular customer in the back end.  In order to show this, we need to create a tab in the customer admin.

In this blog, we shall see, how to create a new tab in the customer admin and to load custom PHTML into it. Let us say, the tab’s name is “Customer Credit”.

Before creating the customer tab, we need to create a new module. We already have a blog on “How to create a new module in Magento 2?” . Please refer the same for more details.

Step 1:

To create a new tab in the admin customer edit, create a xml in the following path

/app/code/Vendorname/modulename/view/adminhtml/layout/customer_index_edit.xml

 

Step 2:

Create a block file in the below path to load the contents when the tab is clicked

/app/code/Vendorname/Modulename/Block/Adminhtml/Edit/Tab/Credit.php

 

I have the block name as “Credit”. The block implements from  TabInterface. The most important function in this class is : getTabUrl()  and isAjaxLoaded() :

getTabUrl()  contain the  code  return $this->getUrl(credit/*/credit, [‘_current’ => true]); equal go to action and execute the complete path of your controller in Magento 2.

 

Step 3:

Following is the routes.xml for creating a controller to make the url valid.

/app/code/Vendorname/Modulename/etc/adminhtml/routes.xml 

 Step 4:

Lets now create a controller with the class name Credit in the below path :

/app/code/Vendorname/Modulename/Controller/Adminhtml/Index/Credit.php

 

Step 5:

Create another xml to mention which phtml file has to load

/app/code/Vendorname/Modulename/view/adminhtml/layout/credit_index_credit.xml

Step 6:

Finally create the phtml file and type your text or implement your logics with block and controller.

/app/code/Vendorname/Modulename/view/adminhtml/templates/credit.phtml

This is our new tab.

Now clear your cache. System – > Cache Management – > Flush Magento Cache

After clearing you cache, your admin will look like the image below…

customer admin edit magento 2

 

Be the first to Know

Subscribe to our blog to get the latest articles directly to your inbox.

Tags

READY TO DRIVE SALES?

Request a Quote Today

Request a Quote

Leave a Reply

19 Comments on "How To Create a Tab in Customer Admin Edit in Magento 2 ?"


Guest
Yasar
1 month 22 days ago

phtml file content is not showing

Guest
pawan kumar
3 months 3 days ago

Hi,
I have tried this format this is not worked for me can you tell more about this i tried in my custom module.I need to insert tempalte in my custom module tab

Guest
kumar
4 months 21 days ago

HOW TO CREATE A TAB IN SALES ADMIN EDIT IN MAGENTO 2 ?

Guest
Vivek Kumar
1 year 14 days ago

Hi jeya,

I have successfully added new tab. I want to add new attribute in this tab.

Please help me.

Thanks

Jeyakiruthika
Author
1 year 1 day ago

Hi Vivek,

Please find the reply to the following three comments from you….

1. Hi jeya,

I have successfully added new tab. I want to add new attribute in this tab.
Please help me.
Thanks
————————————-
2. How To Create a Tab in Customer Admin Edit in Magento 2 ?
————————————-
3. Hi Jeya,
I have followed the same process and successfully added new tab as i need but after click I want to add some custom attribute like image and expire date. Please help.
————————————-

My Reply for the above three comments…

This blog tells you how to create a customer admin tab edit and load a phtml file for the custom purposes. if you want to display the customer attributes alone , the you can go for Magento UI component using customer_form.xml. For instance, customer_form.xml is used to display customer view, account information and addresses section on customer edit page. If you want to show the customer attributes in the custom phtml then need to explicity call the customer attributes using block file.
We will proivde you the blog shortly.

Guest
Vivek Kumar
1 year 14 days ago

Also I want to show this new tab in the last.

Thanks

Guest
Vivek Kumar
1 year 14 days ago

Hi Jeya,
I have followed the same process and successfully added new tab as i need but after click I want to add some custom attribute like image and expire date. Please help.

Guest
anjum
1 year 2 months ago

Hi Jeya,
I have followed the same procedure which u have written above but the new tab is not being created and there are no errors shown.. can you please help me out what the issue is?

Guest
mohan
1 year 2 months ago

How do I go about attaching (or moving) an existing field from “Account Information” to the new tab? I can’t seem to find anywhere to show how to move, for example, Date of Birth, to a new tab (or different fieldset).

Jeyakiruthika
Author
1 year 2 months ago

Hi Mohan,

To answer in brief to your question, we need a separate blog.
We will write a blog on this soon…
Thanks.

Guest
Jose M
1 year 4 months ago

Hi Jeyakiruthika, I need edit and add a field in admin create new customer form, can you help me with that? Thanks!

Jeyakiruthika
Author
1 year 4 months ago

Hi Jose,

Thanks for your question. Here is the reply…

The blog explains how to create a new customer admin tab and load the phtml file to the tab. Since it is a phtml file, you can create own form and save the values to database using Model files.

Does this answer your query. Please let me know.

Subscribe to our blogs for more interesting info on M2.

Guest
Ramesh
1 year 5 months ago

Hi Jeyakiruthika, How can i display custom tab dependent upon customer type. Actually i have two types scustomers then how can i display custom tab to specified customer type.

Jeyakiruthika
Author
1 year 4 months ago

Hi Ramesh,

Sorry for the delayed reply. Here is the response…

This is entirely a different process. You have to check Magento ACL procedure for your module. if your module doesnt have ACL, create acl.xml in module/etc/ folder and mention the resource id for it. Navigate to System > Permissions > User Roles and select or unselect the menus to grant access.

Please let me know if you had already resolved the issue. Also , let me know if you have any further queries.

Thanks.
Please subscribe to our blog page.

Jeyakiruthika
Author
1 year 5 months ago

Hi Ramesh,

I am analyzing this.
Will get back to you shortly.
Thanks.
Please subscribe to our blogs for insights on eCommerce,Magento & QA.

Guest
Georgios
1 year 5 months ago

How do I go about attaching (or moving) an existing field from “Account Information” to the new tab? I can’t seem to find anywhere to show how to move, for example, Date of Birth, to a new tab (or different fieldset).

Jeyakiruthika
Author
1 year 5 months ago

Hi Georgios,

Thanks for your comment.
I am analyzing this. Please give me some time to respond.
Please subscribe to our blog page.
Thanks.

Guest
Abhishek
1 year 9 months ago

Is it only for customer edit page or appears also on new customer page

Jeyakiruthika
Author
1 year 5 months ago

Hi Abhishek,

It appears only in customer edit page not on new customer.
Please subscribe to our blogs.
Thanks.