Magento 1.9 – Programmatically Remove Product Custom Options

csscustom-optionsmagento-1.9

I have custom option called stitching for 500 products.

I am looking for ways to remove it. I don't want to delete them via backend as I would like to retain them if I would like to enable them in future. Is hiding via css display:none the right thing to do?

Custom options

Best Answer

The following instruction will help you to delete all custom options for all products.

If you would like to keep them then it's better to have backup of your current database.
OR even better if you want to hide from CSS, however hiding from css will use little of your resource.

Especially this catalog_product_option table is responsible for holding your all custom options.

Now, to delete your all options you have two choices:

  1. Empty this catalog_product_option table manually from DB.
  2. Do it from code (Recommended)

Doing it from code

Just create a file your_name.php in root and have these code:

<?php
require_once 'app/Mage.php';
Mage::init();

Mage::getModel('catalog/product_option')->getCollection()->walk('delete');

Then run it from browser.

Update
The only downside is that the table catalog_product_entity will be not updated that means all these products with custom options will still have has_options set to 1

This can be fixed with the following query

UPDATE `catalog_product_entity` SET `has_options`= 0 WHERE has_options=1

Note this last query may have impact on bundle products, I don't use these kind of products so do a test before using it on prodution

Please make backup of your database before doing it.

Related Topic