You can use this way by Creating Block file,
<?php
namespace Rbj\Checkout\Block;
class Success extends \Magento\Framework\View\Element\Template
{
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Checkout\Model\Session $checkoutSession,
array $data = []
) {
$this->checkoutSession = $checkoutSession;
parent::__construct($context, $data);
public function getLastOrder()
{
return $this->_checkoutSession->getLastRealOrder()->getEntityId();
}
}
Call Block function in a template file,
echo $block->getLastOrder();
Directly template file, Check using below file, I am not sure its working or not,
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
echo $lastOrderId = $objectManager->get('Magento\Checkout\Model\Session')->getLastRealOrder()->getEntityId();
... View more