Magento 2.x – Add custom attribute to customer model and show on admin panel

You will need to perform some basic steps to create and set a new attribute on the customer model.

  • Create a new module, with a setup script, with the following files:
    • app/code/{CompanyName}/{ExtensionName}/registration.php
    • app/code/{CompanyName}/{ExtensionName}/etc/module.xml
    • app/code/{CompanyName}/{ExtensionName}/Setup/InstallData.php
    • app/code/{CompanyName}/{ExtensionName}/view/adminhtml/ui_component/customer_form.xml

      Note: In contrast to Magento 1, in Magento 2 you now need to add some XML to make custom attributes appear in the edit customer section of the admin.

Afterwards, and before testing, remember to enable the module, clean cache, and do a setup:upgrade.