Get Order Increment Id in Magento
magento, php
Solution
If you're specifically doing this on the checkout success page - in success.phtml - then the code to get the order increment ID is already available in the template, since it is displayed to the customer.
You just need the following:
$orderId = $this->getOrderId();
Note that this won't work on other pages so, for those, you'd need to use:
$orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
Problem
I'm trying to get the Order Increment Id in Magento, on the success.phtml page so that I can use this for affiliate tracking. I'm using the following code, but it is giving an error on the second line; ``` $order = Mage::getSingleton('sales/order')->getLastOrderId(); $lastOrderId = $order->getIncrementId(); ``` The error reads: Fatal error: Call to a member function getIncrementId() on a non-object on line 34: $LastOrderId = $order->getIncrementId(); I was wondering if anyone has any ideas on how to get the Order Increment Id? This is the reference number seen in the admin, usually something like: #1000123