Please could someone help me with what I imagine is a fairly straightforward request?

I am trying to display the current order ID on the checkout confirmation page using the following code.

<?php $order = Mage::getModel('sales/order')->load($orderId); ?>

<p><?php echo $order; ?></p>

It's not working though and in the front-end source code after completing an order I simply see `


Echoing $order is trying to print the entire order object. Also it seems like the actual order object isn't being loaded properly. What you want is:

<?php $order = Mage::getModel('sales/order')->load(Mage::getSingleton('checkout/session')->getLastOrderId()); ?>

<p><?php echo $order->getId(); ?></p>

What do you mean by checkout confirmation page?

In order to show the current order number, the order should be completed at that point. Make sure your order has been completed at the place where you are going to show order number. If order has not created yet, there won't be any order number. So it'll show blank in the frontend.

If order has been created at that point then try the following code.

 <?php $order = Mage::getModel('sales/order')->loadByIncrementId('10000001');
// Assume you know the increment id. (here increment id = 10000001

    <p><?php echo $order->getId(); ?></p>

You can get Order Id using already existing object

<?php $orderId = $this->getOrderId(); ?>

then load order using this order Id and get your required data.

<?php $order = Mage::getModel('sales/order')->load($orderId); ?>

and you can also get Order Id and other detail using below code

$orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
$order = Mage::getSingleton('sales/order')->loadByIncrementId($orderId);

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.