I want to echo the customer name and order id on the checkout success page.

I currently use this line to display the customer name:

<?php $order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId()); echo $order->getCustomerName(); ?>

But that echo the value "Guest guest".

And to load the order ID I use this, but that does also not work:

<p><?php echo $this->__('Your order ID is <strong> %s.</strong>', $this->escapeHtml($this->getOrderId())) ?> </p>

How can I fix this problem?

  • are you doing at success.phtml – Amit Bera Jun 25 '15 at 9:28
  • @AmitBera Yes I do it on success.phtml – JGeer Jun 25 '15 at 9:28
  • is ($this->getOrderId() given order increment id? – Amit Bera Jun 25 '15 at 10:01
  • Did you find the solution? Do you need more info? – Adarsh Khatri Mar 2 '16 at 13:14

To get the order details on the checkout success page, use this

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

and then retrieve the customer info from the order object like this

//If they have no customer id, they're a guest.
if($order->getCustomerId() === NULL){
    echo $order->getBillingAddress()->getFirstname();
    echo "<br/>";
    echo $order->getBillingAddress()->getLastname();
} else {
    //else, they're a normal registered user.
    $customer = Mage::getModel('customer/customer')->load($order->getCustomerId());
    echo $customer->getDefaultBillingAddress()->getFirstname();
    echo "<br/>";
    echo $customer->getDefaultBillingAddress()->getLastname();
  • Strange.Its working for me. are u checking for guest customer.? – Manashvi Birla Jun 25 '15 at 9:16
  • Thanks it is working! But how do I echo the order id? – JGeer Jun 25 '15 at 9:17
  • Mage::getSingleton('checkout/session')->getLastOrderId(); this will print the order id – Manashvi Birla Jun 25 '15 at 9:19
  • 1
    please accept and upvote if it helped – Manashvi Birla Jun 25 '15 at 9:26
  • I tried to get the order ID, but when I past that line, it does not echo the order id. – JGeer Jun 25 '15 at 9:27

Try this:

<?php echo $this->getOrder()->getBillingAddress()->getName();?>

This will echo Customer's Name from Billing Info section.

If you want to get Customer name from register customer rather than billing address then try this:

<?php $order = Mage::getModel('sales/order')->load($this->getOrderId());
if($order->getCustomerIsGuest()){ //if order created as guest
   echo $order->getBillingAddress()->getName();
else //if order created by registered user
   echo $order->getCustomerName();

This should give you desired result.


If give order increment id then you can customer name.

Whenever a customer is placed an order as guest that time customer name is take from billing address.

Try below code:

$order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
    echo $name;
  • I tried you code to load the customer name, but that only works for payment money check. Because that is place the order directly. When I use a payment method that is payed outside our magento store and redirects when it is complete, it does not display the name. – JGeer Jun 25 '15 at 10:25
  • is $this->getOrderId() given order increment id? – Amit Bera Jun 25 '15 at 10:26
  • No it does not given me the order increment id – JGeer Jun 25 '15 at 10:30
  • that issue is here....whenever you have place order using other payment gateway except money check. Bascially magento is carry order id by checkout session variable Mage::getSingleton('checkout/session')->getLastOrderId();. may be it not set.. – Amit Bera Jun 25 '15 at 10:37
  • Do you know how to check and fix this? – JGeer Jun 25 '15 at 10:41

Here i find out the guest user after placing an order/ from an order increment id. and identified as guest. this is i have done in success.phtml page.

$order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());

    $customerData = Mage::getModel('customer/customer')->load($order->getCustomerId());
    $customer = Mage::getModel('customer/customer')->getCollection()
  echo "Guest Checkout";

Change your code

echo $order->getCustomerName();


 echo $order->getBillingAddress()->getName();
  • 4
    Exactly the same has already been suggested in another answer, alongside with an explanation. Please only answer if you can add additional value – Fabian Schmengler Mar 2 '16 at 13:24

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.