Magento 2.x – Add a custom customer attribute on his dashboard page.


In addition of a previous comment where we added a new attribute to the customer  (https://www.offset101.com/magento-2-x-add-custom-attribute-customer-model-show-admin-panel/ ), here, we are going to add this attribute to the dashboard page of the customer.

 

At first, we need to know that all fields are rendered in the customer-module, so you will need to override the following file

to the corresponding one on your theme (or module).

 

Afterwards, and keeping the best Magento practice, we will need to override with a preference, the following Magento Block:

To do so, let’s perform the following steps, and create the following files:

  • /Company/Custom/Block/Magento/Customer/Form/Edit.php
  • /Company/Custom/etc/di.xml

     

After adding it, you will be able to add your custom field, in the edit.phtml overrided before, with the following line of code:

 

Remember to clean cache, and do a setup upgrade.

Happy Coding!