Add Custom Option in Product Programmatically in Magento 2.

Magento 2, Product with custom option used to allow customers to customize the product as per the need from a set of different Custom options.

The custom option is a native feature of Magento and you can add the Custom option by Admin side in product Section.

You can add multiple types of custom option like Text field, Text area, Dropdown, Checkbox, Radio button, File(Image), Multiple Select, Date, Date & Time, Time.

If you want to add custom option programmatically to Product you need to use below code in your module.

From Template file, You need to call Product SKU, which you want to add Custom options,

$sku = “24-MB05”;
$product = $block->addCustomOption($sku);

add Custom Option
add Custom Option

I have taken SKU as 24-MB05 from Magento Sample data.