Anthony
Anthony

Reputation: 123

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!

Upvotes: 1

Views: 2868

Answers (2)

Barbanet
Barbanet

Reputation: 493

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.

Upvotes: 2

Anton S
Anton S

Reputation: 12750

You have the order increment number ther so load the order and get the variable from order object

Upvotes: 0

Related Questions