1

I want to get last order's order id at any page?

1

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

<?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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy