Magento 1.9 – How to Get Selected Values of Product Custom Options?

custom-optionsmagento-1.9product

I have a virtual product and it consists with various types of custom options such as drop-downs, text fields, radio buttons etc. Once the place order clicks I'm firing an event observer. There I want to get the selected values of all these custom options.

How to achieve this? I can get the option titles. But can't get the selected values of them.

Best Answer

Try the below code,

    $order = $observer->getEvent()->getOrder();
    $items = $order->getAllVisibleItems();
    foreach ($items as $item) {
    $options = $item->getProductOptions(); 
    $customOptions = $options['options'];   
    if(!empty($customOptions))
    {
      foreach ($customOptions as $option)
      {     
         $optionTitle = $option['label'];
         $optionId = $option['option_id'];
         $optionType = $option['type'];
         $optionValue = $option['value'];
      }
   }