How can delete all custom product attributes from database and keep only system attributes in Magento 2.4
2 Answers
You can acheive the same by Mysql query
DELETE FROM `eav_attribute` WHERE `eav_attribute`.`entity_type_id=4` AND `eav_attribute`.`is_user_defined`=1";
entity_type_id=4 for \Magento\Catalog\Model\Product::ENTITY
is_user_defined=1 means that that attribute is created by user and can be modified.
Try below script
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
$eavSetup->removeAttribute(\Magento\Customer\Model\Customer::ENTITY, 'custom-attribute-code'