Magento: Get Custom Option Value from Order

This article contains code snippet to get custom options value of all products in any Magento order.

Suppose, there is a product with a custom option dropdown list. You chose one of the option from the dropdown list and purchased that product. The code below fetches product’s custom option value selected in any particular order.

Here is the code:-


$incrementId = '100000042';
$order = Mage::getModel('sales/order')->loadByIncrementId($incrementId);
foreach ($order->getAllItems() 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'];
	}
    }
}

Hope it helps. Thanks.