2

I'm trying to get the last order number in magento 2. I've tried getting it this way.

$objectManager = \Magenato\Framework\App\ObjectManager::getInstance();
$checkout_session = $objectManager>get('\Magento\Checkout\Model\Session');
$order = $checkout_session->getLastRealOrder();
$orderId= $order->getEntityId();
$number = $order->getIncrementId();

but returns null.

Please assist , Thank you.

1 Answer 1

1

To get the last order number ...

$objectManager = \Magenato\Framework\App\ObjectManager::getInstance();
$checkout_session = $objectManager>get('\Magento\Checkout\Model\Session');
$order = $checkout_session->getLastRealOrder();
$orderNumber = $order->getId();
echo $orderNumber;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.