Get Free Audit

How to Add Custom Attribute To Customer Grid in Magento 2

Jan 22, 2019

7447 Egor Shubin

How to Add Custom Attribute To Customer Grid in Magento 2

When a new customer registers at your Magento 2 online shop, he is required to fill in certain fields, such as first name, last name, email. He or she may want to provide some additional information. For that purpose, we need to create our own fields which will be used in a registration form. If you have Magento 2 Commerce version, new fields can be created by adding new customer attributes in the backoffice.

I will look into the following aspects:

Add new customer attribute in Magento 2 Commerce
Appearance in Customer Grid
Manage Labels/Options
Customer Address Attribute

Add new customer attribute in Magento 2 Commerce

In the backoffice menu click Stores and choose Customer under Attributes subcategory.

Add new atribute Magento 2

You’ll see a list of customer attributes. Perhaps the attribute you want to create already exists, but is currently disabled. So all you need to do is to switch it on.

If you haven’t found the attribute you need, click the Add new attribute button.

Add new attribute button Magento 2

Let’s suppose we have an online shop selling travelling equipment and we need to create a field asking if a customer ready to travel.

Enter the name of the field in Default Label and an Attribute code that must be unique.

attribute properties ready for magento 2

Then, choose from different types of input:

  • Text Field,
  • Text Area,
  • Multiple Line,
  • Date,
  • Dropdown,
  • Multiple Select,
  • Yes/No,
  • File (attachment),
  • Image File.

I will choose Yes/No input type.

Input type Magento 2

You will need to complete other settings as well:

  • Values Required;
  • Default Value;
  • Input Validation. You can choose whether the field must be validated (if not – leave “None”), and if yes – then by which parameter: Alphanumeric (should contain letters, numbers, punctuation marks), Numeric Only, Alpha Only (only letters), URL, Email, Length Only;
  • Input/Output Filter: None, Strip HTML tags, Escape HTML entities (e.g. < will be replaced with &lt; and so on).

Values required Magento 2

In our case the field won’t contain any input text, that’s why we don’t fill in both Input Validation and Input/Output Filter.

Storefront properties block of settings is necessary to fill in, if your attribute will become a field in forms for your customers on the site. If yes, you can choose the forms where it must appear. You should also set up the position of the field in the form (I set it at 5).

Storefront properties Magento 2

So let’s check out what we get after adding our attribute. Save it and open registration form.

Igor Dragun
Partner With Us Let's discuss how to grow your business. Get a Free Quote.
Talk to Igor

create new customer account magento 2

Here’s our field, it’s 5th in the list. It looks the way we wanted to, with “yes/no” dropdown.

Appearance in Customer Grid

There’s another block of settings concerning customer grid.

Appearance in Customer Grid Magento 2

Let’s go to attribute settings, enable Add to Column Options and save.

Go to Customers -> All Customers, and you will see the Customer Grid, an indexed version of it. To see the changes we made, update the index first. In console use command bin/magento indexer:reindex customer_grid.

_22apply_to_22_attribute_option

"Apply To" Attribute Option for Magento 2

Take your online store to the next level with BelVG module

Download here

After rebuilding the index you’d expect to see the new customer attribute in the columns, but it’s still not there.

Customers Magento 2

In the Customer Grid you can add a column from existing attributes. Press Columns button and tick our new attribute “Ready for travel?”.

New attribute magento 2

 

Afterward you’ll be able to see the new attribute as a column.

Manage Labels/Options

You can create a label name in different languages and set up its reflection depending on the country of each customer. Go to Manage Label / Options tab.

Attribute information magento 2

Customer Address Attribute

Bear in mind that if you wish to add an attribute concerning customer’s address, you should create a Customer Address Attribute. In backoffice menu click Stores and choose Customer Address under Attributes heading. From then on the mechanism of working with an attribute in the same as has been already described above.

FAQ

Question: Can’t export csv and xml with a custom attribute

Answer: Magento 2 export creates a file only with those columns that are visible in customer grid. So add the column to the customer grid as it was described in this article.

Diversify your customer management with BelVG’s Customer Attributes module for Magento.

magento custom development

Magento Custom Development

Take your online store to the next level with BelVG Magento Custom Development

Visit the page
Igor Dragun
Partner With Us Looking for a partner to grow your business? We are the right company to bring your webstore to success. Talk to Igor

4 Comments

  1. Hi, Alexander! I suppose that you are using a version of Magento that is different from the one featured in the article.

  2. Hi, Javaria! Perhaps you are using a different version of Magento. In this article, we used Magento Commerce for demonstration purposes.

  3. We are using Magento 2.2.6 but I can’t find the “Customer” under Attributes… Where is it?

Post a new comment

BelVG Newsletter
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.
Email *