Attributes are the building blocks of your product catalog and it illustrates the characteristics of a product.
Sometimes while handling multiple store views or websites through a single Magento may mess up attributes on different scope levels. It happens due to the test products and its attributes created. A developer may want to clean the DB after the tests. It’s almost impossible to find and delete such attribute values from the admin panel and doing it manually takes time and effort. Instead, I’ve come up with a solution to delete product attributes programmatically in Magento.
When you delete an attribute, it is automatically removed from any related products and attribute sets.
Method to Delete Product Attributes Programmatically in Magento:
require_once 'app/Mage.php'; umask(0); Mage::app(); $attr = 'whatsapp_share'; //attribute code to remove $setup = Mage::getResourceModel('catalog/setup', 'core_setup'); try { $setup->startSetup(); $setup->removeAttribute('catalog_product', $attr); $setup->endSetup(); echo $attr . " attribute is removed"; } catch (Mage_Core_Exception $e) { print_r($e->getMessage()); }
Implement the above code to delete product attributes programmatically in Magento!