Magento – Display order ID on checkout success page

checkoutorder-statusorders

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 `

Best Answer

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>