i created an own module for a new block in success.phtml and created a Plugin in my own module. Read my old post here: How to get an order id in success.phtml block?

In my success.phtml file i have the following code:

$order = $block->getCurrentOrder();
$orderId= $order->getId();

On the successpage i get the following error: Call to a member function getId() on null in


Why its not possible to access the function?? Any error on the Code?

  • Have you tried: $block->getOrderId();
    – harri
    Oct 2, 2017 at 15:23
  • Are you sure that your checkout success page phtml file location is app/code/Meta/Orderpage/view/frontend/templates/order/success.phtml?
    – Amit Bera
    Oct 2, 2017 at 15:40
  • Also, don't the as same question,Please comment on your previous question or update the question?
    – Amit Bera
    Oct 2, 2017 at 15:42

1 Answer 1


This is what I did in my success.phtml file to get an order ID, and it works everytime:

$orderID = $this->getOrderId();

Then of course, if you want to show it, simply do something like this:

echo "Order ID: " . $orderID;

Perhaps it is the "$this" part that makes the difference.

If it is any help, the path to my module and the success.phtml file is similar to this:


I hope this helps and answers your question.

  • This return the order Increment ID not the Order ID Mar 25, 2018 at 7:08

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