Magento – How to add a customer’s email to the sales invoice

customer-addressemailemail-templatessales-ordershipping-address

Essentially looking to add customer email to our customer's receipts (invoices) and sales order emails that are generated to dispatch/couriers as well etc.

With a bit of searching I've established the best way to do this is simply to add this variable through the magento admin system area. So below:

System > Configuration > Customers > Customer Configuration > Address Templates

This brings up all of the address templates fields for text, html, pdf etc.

So I've added what I believe to be the variable name need into each box here.

So for example html is now:

{{depend prefix}}{{var prefix}} {{/depend}}{{var firstname}} {{depend
middlename}}{{var middlename}} {{/depend}}{{var lastname}}{{depend
suffix}} {{var suffix}}{{/depend}}
{{depend company}}{{var
company}}
{{/depend}} {{if street1}}{{var street1}}
{{/if}}
{{depend street2}}{{var street2}}
{{/depend}} {{depend
street3}}{{var street3}}
{{/depend}} {{depend street4}}{{var
street4}}
{{/depend}} {{if city}}{{var city}}, {{/if}}{{if
region}}{{var region}}, {{/if}}{{if postcode}}{{var
postcode}}{{/if}}
{{var country}}
{{depend
telephone}}Mobile: {{var telephone}}{{/depend}} {{depend
fax}}
Landline: {{var fax}}{{/depend}} {{depend vat_id}}
VAT:
{{var vat_id}}{{/depend}} {{depend email}}Email: {{var
email}}{{/depend}}

So the key line for me being the below:

{{depend email}}Email: {{var email}}{{/depend}}

Other than this 1 change, is there anything else I'm failing to do to make this variable be added to the shipping address templates?

Best Answer

You can get the customer email like this in the invoice or order templates:

{{var order.getCustomerEmail()}}

SO you can try to add

Email: {{var order.getCustomerEmail()}}

after

{{var order.shipping_address.format('html')}}

[Edit]
For pdf you should replace this from Mage_Sales_Model_Order_Pdf_Abstract::insertOrder

$shippingAddress = $this->_formatAddress($order->getShippingAddress()->format('pdf'));

with

$shippingAddress = $this->_formatAddress($order->getShippingAddress()->format('pdf').'|'.Mage::helper('sales')->__('Email:').$order->getCustomerEmail());  

Of course you shouldn't edit the core code.
You have to copy the file to the local folder. You cannot do a simple override because it's an abstract class.

Related Topic