Skip to content

How to add customer attribute programmatically in Magento 2

Today, we will guide you on how to add customer attribute in Magento 2 programmatically. so now I am going to explain step by step.

You can download the module from the below GitHub repository: 

How to add customer attribute programmatically in Magento 2

Step 1: Create setup file InstallData.php in the Setup directory

we used the file: app/code/Dev/CustomerAttribute/Setup/InstallData.php

Step 2: Show Customer Attribute in Register form

We will add our phtml files to ‘form.additional.info’ reference name using
Dev/CustomerAttribute/view/frontend/layout/customer_account_create.xml

Now, create additional.phtml file, we will write the code to show the additional textbox:
Dev/CustomerAttribute/view/frontend/templates/additional.phtml

Now Run the upgrade command to install our module.
You need to run a command using SSh from the root of your Magento instance. If you want to more command list then refer our another post which Magento 2 useful commands lists.

After you can check your new group code attribute at admin panel and register form.

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Share via
Copy link
Powered by Social Snap