I have created custom options programatically with reference of below url : https://webkul.com/blog/create-custom-option-programmatically-in-magento2/ How to update any option value or option details programatically for options which are already added in product.

2 Answers 2

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$productId = 1;
$_product = $objectManager->create('Magento\Catalog\Api\ProductRepositoryInterface')->getById($productId, true);
$newValues = array();
foreach ($_product->getOptions() as $option) {
           $optionValues = $option->getValues();
  foreach($optionValues as $value)
            $newValues[$value->getId()]['option_type_id']= $value->getId();
                $newValues[$value->getId()]['title']= 'Custom Title';
                $newValues[$value->getId()]['price']= 100;
                $newValues[$value->getId()]['price_type']= 'fixed';


Try this:

$product->setData('your_option_name', $yourOptionValue);


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.