Magento 2 Remove Product Attribute Programmatically

To remove product attribute programatically, create InstallData.php and and define the method intsall() as follows

File : app/code/PHPCodez/First/Setup/InstallData.php

 namespace PHPCodez\First\Setup;
 use Magento\Eav\Setup\EavSetup;
 use Magento\Eav\Setup\EavSetupFactory;
 use Magento\Framework\Setup\InstallDataInterface;
 use Magento\Framework\Setup\ModuleContextInterface;
 use Magento\Framework\Setup\ModuleDataSetupInterface;

class InstallData implements InstallDataInterface
 private $eavSetupFactory;

public function __construct(EavSetupFactory $eavSetupFactory) {
 $this->eavSetupFactory = $eavSetupFactory;
 public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context){
 $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);

Purge cache and deploy static content by running the following commands.

php bin/magento cache:flush
php bin/magento setup:static-content:deploy -f

One thought on “Magento 2 Remove Product Attribute Programmatically”

  1. This is a useful article but I would like to mention that using product attributes without taking permission from the original source, if any, is unethical and should not be performed.

Leave a Reply

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