I have code for last order detail but I want last 5 orders. For last order detail code is:
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$orderDatamodel = $objectManager->get('Magento\Sales\Model\Order')->getCollection()->getLastItem();
$orderId = $orderDatamodel->getId();
$order = $objectManager->create('\Magento\Sales\Model\Order')->load($orderId);
$orderItems = $order->getAllItems();
foreach ($orderItems as $item) {
$product_name= $item->getName();
$product_id= $item->getProductId();
}
I want last 5 oders detail.