I am in Product Detail Page. I want to show how many customers already had bought this product.
$time = time();
$to = date('Y-m-d H:i:s', $time);
$lastTime = $time - 86400; // 60*60*24
$from = date('Y-m-d H:i:s', $lastTime);
$items = Mage::getResourceModel('sales/order_item_collection')
->addAttributeToSelect('order_id')
->addAttributeToSelect('created_at')
->addAttributeToFilter('created_at', array('from' => $from, 'to' => $to));
$soldCount = 0;
foreach ($items as $item) {
$soldCount += $item->getQtyOrdered() - $item->getQtyCanceled() - $item->getQtyRefunded();
}
<?php if (count($soldCount) > 0):?>
<div class="order-enticer button--l animated fadeInDown">Good Choice...
<b><?php echo $soldCount;?></b>
people have ordered this in the past 24 hours.</div>
<?php endif; ?>