I want to show values from Custom option text field in product view page if customer already ordered the product. I don't have fixed options attribute they may change like custom size, sleeve size, etc. I am trying following code and fetch last order. I don't know how to get product custom options (text field) attribute dynamically.
if(Mage::getSingleton('customer/session')->isLoggedIn()){
$customer = Mage::getSingleton('customer/session')->getCustomer();
$email= $customer->getEmail();
$_customer = Mage::getModel('customer/customer');
// get order id
$orders1 = Mage::getResourceModel('sales/order_collection')
->addFieldToSelect('*')
->addFilter('customer_email', $email)
->addAttributeToSort('created_at', 'DESC')
->setPageSize(1);
$id= $orders1->getFirstItem()->getId();
$order = Mage::getModel('sales/order')->load($id);
//get all items
$items = $order->getAllItems();
$itemcount= count($items);
$data = array();
$i=0;
//loop for all order items
foreach ($items as $itemId => $item)
{
$data[$i]['name'] = $item->getName();
$data[$i]['attr'] = $item->getAttributeName();
}