Magento 2 Get Last order in any page using Checkout Session. You can fetch Last order id of order by Magento\Checkout\Model\Session Object.
You need to create __construct( ) function for define dependency of Session Class
1 2 3 4 5 6 7 8 9 10 11 12 13 | <?php private $checkoutSession; /** * Constructor * * @param Session $checkoutSession */ public function __construct( \Magento\Checkout\Model\Session $checkoutSession ) { $this->checkoutSession = $checkoutSession; } |
Call method to get last order id using below way,
$orderId = $this->checkoutSession->getData(‘last_order_id’);
$orderId is your recent order id for a store.