Here is my code, but it is only generating the simple product SKU where I want to get it for the configurable product page also. I used it to restrict a block on a simple and configurable product page.
$_cId = 0;
if(Mage::getSingleton('customer/session')->isLoggedIn()) {
$customerData = Mage::getSingleton('customer/session')->getCustomer();
$_cId = $customerData->getId();
}
$orderItems = Mage::getResourceModel('sales/order_item_collection')
->addFieldToFilter('sku', $this->getProductInfo()->getSku())
->toArray(array('order_id'));
$orderIds = array_unique(array_map(
function($orderItem) {
return $orderItem('order_id');
},
$orderItems('items')));
$orderCollection = Mage::getResourceModel('sales/order_collection')
->addFieldToFilter('entity_id', array('in' => $orderIds))
->addFieldToFilter('customer_id', array('eq' => $_cId));
$orderCollection->getSelect()->group('customer_id');
$customerCollection = Mage::getModel('customer/customer')->getCollection()
->addFieldToFilter('entity_id', array('in' => $orderCollection->getColumnValues('customer_id')));
foreach ($customerCollection as $customer) {
// Code
}