How to add an custom attribute in Magento 2

The products attribute in Magento 2 is basically the properties of the products which help the customers to choose the different sizes, colors, and weights, etc.  

Magento 2 allowed us to create the attribute as many as we want. We have can choose any type for our attribute like dropdown, visual swatch, etc. In this blog, we are making an attribute that has the dropdown type. 

In order to make this attribute for your product follow the following steps.

  1. First of all, open the Magento 2 admin or dashboard and click on the store at the bottom of the left sidebar.

    Untitled_design_1.png

  2. Then new menu shows now click on the product under the attribute.

    Untitled_design_1__2.png

  3. Then click on the new attribute at the top right of the page and a new page will open which is look like this.

    Untitled_design_2__1.png

  4. Now give a name to your attribute in the input label. I give a name Example to the attribute and then select the type of attribute. I select the dropdown type for this attribute you can choose any type you want.

    Untitled_design_5__1.png

  5. Now configure the Advanced properties give the Attribute Code to your attribute. If you don't give an Attribute Code Magento 2 will automatically generate the attribute code as the default label name. 

    Choose the scope value for your attribute. Magento 2 is a multi-language platform. If you don’t want the attribute value to depend on a website or any language. It is better to choose the Globe option.


    Untitled_design_6_.png

  6. If you want to use your attribute in rule conditions for cart prices. Choose Yes in the Use for Promo Rule Conditions.

    Choose Yes in the Visible on Catalog Pages on storefront if you want to display your attribute on the product page in additional options.

    If you want to add an attribute value in a PHP product object Choose Yes in the Use in the Product listing.

    For sorting orders choose Yes in Used for Sorting in the Product listing.

    Untitled_design_8_.png


  7. Now configure the storefront properties for this according to your need. By default, the use in search option is No

    Untitled_design_7_.png

  8. Now Click on the Save Attribute button

    Untitled_design_9__1.png

  9. After click on the save attribute, you will see the popup message that your attribute is saved. If you don’t find your attribute here you can simply search your attribute by your attribute code as I did you can see in the image below.

    Untitled_design_10__1.png

If you need a Magento Developer, visit Magento Development Agency.