I have the following code. The drawback of the code is it is getting all custom options for a product while I want to get only those options which are selected by the customer on the product page.
$items = $order->getAllItems();
foreach ($items as $item) {
$product = Mage::getModel('catalog/product');
$prodSku = $item->getSku();
$productId = $product->getIdBySku($prodSku);
$product->load($productId);
$product = $item->getProduct();
$productId = $item->getItemId();
$options = $product->getOptions();
foreach($options as $_option) {
echo $_option->getTitle();
}
}