Web Analytics

Fill the form & Get Installation Support

How to create customer attribute programmatically in magento2?

For example, when we create a mobile number customer attribute in Magento 2,  we need to create a module to add new customer attribute in Magento2.

Create a registration.php file to the following path

Create module.xml file to the following path  app/code/Magemonkeys/CustomerAttribute/etc/module.xml which define our module setup version to setup_module table.

Then, we need to create an extension_attributes.xml file to the following path app/code/Magemonkeys/CustomerAttribute/etc/extension_attributes.xml

which defines our mobile number customer attribute.

Pass Classname in extension_attributes.xml as Magento\Customer\Api\Data\CustomerInterface because its a base Customer interface to create customer attributes in Magento2.

Set attribute code as your customer attribute code and define type as a string.

For Create Customer attribute we need to define InstallData.php file to the following path app/code/Magemonkeys/CustomerAttribute/Setup/InstallData.php which adds an entry to our database for custom mobile number attribute.

Now Run the upgrade command to install our module using SSh from the root of your Magento instance.

Now you can check your new mobile number attribute at the admin panel.

Go To, Customers -> All Customers -> Edit any Customer.

Fill the below form if you have any Magento programming need.

    Recent Articles

    Author Info

    Author Image

    Magento Certified Developer

    Hire J. Lakum

    Get a Free Quote

      /* second popup */

      Connect With Us