1

I was wondering how I could get a customer's email address to appear right underneath their Telephone number on an invoice in the "Sold to:" section.

The following is how the "Sold to:" section currently looks,

John Doe
123 Fake Street
Beverly Hills, California, 90210
United States
T: (555) 555-5555

and I want it to look like,

John Doe
123 Fake Street
Beverly Hills, California, 90210
United States
T: (555) 555-5555
johndoe@johndoe.com

Edit:
After some googling I stumbled upon this gem which worked for me just in case anyone else runs into the same issue.
[broken link]

  • You need this in invoice pdf – saravanavelu Jun 12 '15 at 17:46
  • Do you know how I add it? I tried adding {{depend email}}{{var email}} {{/depend}} but that didn't work. I am not 100% sure that "email" is the correct variable. Can you elaborate on "You need this in invoice pdf"? – Ivan Alvarado Jun 12 '15 at 17:52
  • Regarding invoice there are many things,email,PDF where you need to add email after telephone – saravanavelu Jun 12 '15 at 17:58
  • Do you know if that is the correct variable I add {{var email}}? Is it called something else because I tried what you suggested and that doesn't seem to work. I'm guessing I probably have the wrong variable name. – Ivan Alvarado Jun 12 '15 at 18:11

2 Answers2

1

Here is the solution to add the customer's email to invoice pdf as well as the email.

1) to add customer's email to invoice pdf. open file app/code/core/Mage/Sales/Model/Order/Pdf/Abstract.php

find this line

$billingAddress = $this->_formatAddress($order->getBillingAddress()->format('pdf'));

and replace with

$billingAddress = $this->_formatAddress($order->getBillingAddress()->format('pdf'));

2) to add the customer's email to invoice email, change the below files

Change the function sendEmail() located in file app/code/core/Mage/Sales/Model/Order/Invoice.php Add $email in the template parameters.

$email = $order->getCustomerEmail();
$mailer->setTemplateParams(array(
                'order'        => $order,
                'invoice'      => $this,
                'comment'      => $comment,
                'email'        => $email,
                'billing'      => $order->getBillingAddress(),
                'payment_html' => $paymentBlockHtml
            )
        );

Now you can access this variable like {{var email}} in the email template located in app/locale/en_US/template/email/sales/invoice_new.html

P.S. I will advice not to make changes in the core file

Manashvi Birla
  • 8,833
  • 9
  • 27
  • 53
  • Thanks for your answer. It's not considered best practise to edit core files in app/code/core as this is not update-safe so it would be better to rewrite these files and make your changes there. Maybe you'd like to update your question? – Anna Völkl Jun 13 '15 at 06:53
  • yes exactly, i mentioned in my answer too. wait let me edit my answer again – Manashvi Birla Jun 13 '15 at 07:04
  • 1
    "replace with" code is exactly the same with "find this line" mentioned above ! – Zinat Jul 05 '16 at 09:07
0

You can get the customer email in 'Sold to' in invoice PDF or order templates like this:

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

In pdf you should replace this from Mage_Sales_Model_Order_Pdf_Abstract::insertOrder

$billingAddress = $this->_formatAddress($order->getBillingAddress()->format('pdf'));

with

$billingAddress = $this->_formatAddress($order->getBillingAddress()->format('pdf').'|'.$order->getCustomerEmail()); 

Tested in Magento ver. 1.9.2.4

Reference: Marius Answer How do I add a customer's email to the sales invoice?

Purushotam Sharma
  • 1,657
  • 2
  • 26
  • 59