How to Delete Product Attributes Programmatically in Magento
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
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!
Please feel free to post your doubts in the comments section below, I’d be happy to help π
Rate the blog with 5 stars if found useful.
Sanjay Jethva
Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe.
His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.
Prev
How to Export Magento Products in XML File
How to Convert Attribute type from TEXT to DROPDOWN in Magento
Next