I created magento 2 custom option programmatically like this:
$options[] = [
'title' => 'cthulu',
'type' => 'field',
'is_require' => false,
'sort_order' => 2,
'price' => 0,
'price_type' => 'fixed',
'sku' => 'cthulu',
'max_characters' => 20,
];
$options[] = [
'title' => 'comment',
'type' => 'field',
'is_require' => false,
'sort_order' => 2,
'price' => 0,
'price_type' => 'fixed',
'sku' => 'comment',
'max_characters' => 50,
];
foreach ($options as $option) {
$customOption = $this->customOptionFactory->create(['data' => $option]);
$customOption->setProductSku($product->getSku());
$customOptions[] = $customOption;
}
$product->setCanSaveCustomOptions(true)
->setOptions($customOptions)
->setHasOptions(true)
->save();
the custom option save successfully, now i want to delete the custom option programmatically, is there a way to do this?