enter image description here

How can I save this custom value in database and get in the cart page with the custom option ?

  • When you add custom option, it is already saved in database and also shown on cart page. – Kishan Patadia Jun 5 '17 at 12:38
  • @krishan Patadia i have to add two fields when click custom option i want to add these two field in database – Rahul Katoch Jun 5 '17 at 12:40
  • Which two fields ? – Kishan Patadia Jun 5 '17 at 12:41
  • i added one custom option and two value one is free and second is payed and i have to add two fields in payed one is option and other is textarea how i save these two fields – Rahul Katoch Jun 5 '17 at 12:49
  • 1
    @ Keyur Shah can you please tell me how i save these two attribute value i have to make one attribute and make two two value on is free and second is payed if user click in payed option and open two fields i want save these two fields with attribute value – Rahul Katoch Jun 6 '17 at 11:18

I think you should use, catalog_product_type_prepare_full_options event because this event triggered just before the product with its custom options is converted to a quote item.

In this event you can get added product object $product object by using,

$product = $observer->getEvent()->getProduct();

Now you can add your custom option like,

$infoOptions[] = array(
                            'label' => "YOUR_OPTION_LABEL",
                            'value' => "YOUR_OPTION_VALUE",

you can update this option according your requirement,

Now just add this custom option like,

Add this custom option by

 $product->addCustomOption('additional_options', serialize($infoOptions));       
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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