I am running Magento 2.2 and I want to get the order id on the success page.

$block->getOrderId() // returns 000000008 for example

I do not want 000000008, but the real ID from the database, like 11616. How could I do that on the success page?


  • Please specify the file where you are using this code. You should try getting order object there and then you can use $order->getId() . – Sarvagya Jan 8 '19 at 10:19
  • this code magento is using on order success.phtml file. – Naisa purushotham Jan 8 '19 at 10:39

you need to customize prepareBlockData in vendor/magento/module-checkout/Block/Onepage/Success.php .

Just need to change one line

'order_id'  => $order->getIncrementId()  to 'order_id'  => $order->getId()

Note: Recommended way to write files . Don't change core files, create block and override with < preference > in di.xml file.


Your Answer

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

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