Search code examples
magentomagento-1.5

Magento 1.5.1 - How can I add the customer's billing email address to success.phtml


I've added the following code to the Magento 1.5.1 order confirmation page (success.phtml):

<?php
    $_order_id = Mage::getSingleton('checkout/session')->getLastOrderId(); // here I get the Oreder ID
    $_order->load($_order_id);
    $customer = Mage::getSingleton('customer/session')->getCustomer();
    $email = $customer->getEmail();  // To get Email Address of a customer.
?>

An email confirmation was sent to: <?php echo $email ?>

Unfortunately the email variable is empty/null.

Does anyone know how to efficiently get this data? Obtaining First and Last name would be a bonus.

Keep in mind that guest checkout is allowed, so we may not have a customer record in all cases. In any case, I need the billing email address assosicated with the order (guest checkout or not.)

Thanks!


Solution

  • If you got the Order object maybe you can use:

    $order->getBillingAddress()->getEmail();
    

    I think that this method it better because you can use it for Guest Customers too.