I have a custom HTML on cart page with some checkboxes.
I am getting All the selected checkboxes in my observer "checkout_cart_update_items_before" I am able to update cart item prices in this observer.
Now on cart update I want to create these selected checkboxes as Custom option to cart items and display them with all items in cart.
Following is the code that I have tried to create Custom options.
$item->addOption(
array(
'code' => 'logo_options',
'value' => serialize($logo_positions),
)
);
if ($logoOptions = $item->getOptionByCode('logo_options')) {
$options = $item->getProductOptions();
$options['logo_options'] = unserialize($logoOptions->getValue());
item->setProductOptions($options);
}
$item->save();
Below is a screenshot of Cart.
Best Answer
Try below code to save your custom options' data.
You need to create arrays for each of the options you want to add to your product. I have used static data but you can do it with your dynamic data.
Now to set this data as Product options, Use code,
This will add your data to product as options. See screenshot.