1

how I can delete / remove Customizable Options for all products?

Thank you

enter image description here

1 Answer 1

2

Try below code

    ini_set('display_errors', 1);
    error_reporting(E_ALL);
    include('app/bootstrap.php');
    use Magento\Framework\App\Bootstrap;
    $bootstrap = Bootstrap::create(BP, $_SERVER);
    $objectManager = $bootstrap->getObjectManager();
    $state = $objectManager->get('Magento\Framework\App\State');
    $state->setAreaCode('global');

    $products = $objectManager->get('\Magento\Catalog\Model\Product')->getCollection();
    $count = 0 ;
    echo 'Custom Option Remove Start.<br/>';
    foreach ($products as $product) {
        $product = $objectManager->get('\Magento\Catalog\Model\ProductFactory')->create()->load($product->getId());
        if ($product->getHasOptions()) {
            $temp = [];
            $product->setOptions($temp);
            $product->setHasOptions(0)->save();
            echo "Update ".$product->getName()." ID:".$product->getId()." <br/>";
            $count++;
        }
    }
    echo 'Custom Option Remove Done.';
6
  • Hi thank you, but I don't know why after execution I have a blank page, you have any idea?
    – Robert
    Commented May 30, 2021 at 12:32
  • You have no any custom option product that why. have you check this line is print or not echo 'Custom Option Remove Start.<br/>';
    – Msquare
    Commented May 30, 2021 at 12:49
  • I have a lot of custom options there but the file after I loaded is blank
    – Robert
    Commented May 30, 2021 at 13:12
  • in fact I observe that every code that I put in the php file is blank ...
    – Robert
    Commented May 30, 2021 at 13:25
  • I enable reporting and I have this error: Fatal error: Uncaught Error: Class 'Magento\Framework\App\ObjectManager' not found in /home/public_html/rm_co.php:5 Stack trace: #0 {main} thrown in /home/public_html/rm_co.php on line 5
    – Robert
    Commented May 30, 2021 at 13:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.