Add Yes/No Attribute in Magento 2 programmatically

In Today’s tutorial, we will learn about How to Add Custom Yes/No Boolean Product attributes programmatically using Data Patch in Magento 2.

Here, we will learn to add product attributes programmatically with the help of a data patch in Magento 2. A data patch is a class that stores instructions for data modification. Using a data patch we can add custom product attributes in Magento 2 by creating a PHP file.

Before starting, I’m sure you have already created your custom module,

If not follow this quick tutorial on How to create your first custom module in Magento 2.

Now create AddCallForQuoteAttribute.php in your module directory followed by Setup\Patch\Data

Using the above way you can easily add new custom yes/no (boolean) attributes in products.

You can change this according your requirement.

Thanks for visiting, See you in the next blog!!

Posts you might interested in:

Securely render Javascript inside Magento 2 template files using PHP

Magento 2: How to get a dynamic Base URL Path in XML?

How to remove/disable add to compare in Magento 2?

Leave a Reply

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