Using customer first name in order confirmation email

13,023

[EDITED] You can't use PHP code in your email-templates directly. If you want to insert dynamic data into your email-templates, you have two possibilities:

a) In every transactional email you can access the methods of the model, which is in charge for the transactional email, it is: for mails dealing with orders, this is the order-Model, for mails dealing with newsletters, this is the newsletter-model and so on. You can access the methods with the syntax:

{{var model.method()}}

So, in your case, to access the customer's first name in an order confirmation email, you need to look for a suiting method in the order Model, which is getCustomerFirstname() . Then you can call it, following the given syntax:

{{var order.getCustomerFirstname()}}

b) You can include dynamic data into your email-template by creating a custom phtml-template and including it into your email-template via the {{block}} directive (as pointed out by benmarks in the comment below)

Share:
13,023
Russ Back
Author by

Russ Back

Updated on July 14, 2022

Comments

  • Russ Back
    Russ Back almost 2 years

    I've seen a bunch of articles (mostly 3-5 years old) detailing various methods of getting the customer's first name into the order confirmation email but I just get either a blank, or unparsed PHP.

    For example this:

    <?php echo $this->__('Hello, %s', Mage::getSingleton('customer/session')->getCustomer()->getFirstname()); ?>
    

    Renders in the email like this:

    __('Hello, %s', Mage::getSingleton('customer/session')->getCustomer()->getFirstname()); ?>

    Could somebody point me in the right direction? This is on Community Edition 1.7.

    Thanks

  • benmarks
    benmarks almost 11 years
    While your answer is suitable, "you can't use PHP code in your email-templates" should be qualified. The content of the message body is not parsed as PHP, but take a look at the order templates which include PHP-parsed content (templates) via the {{block}} param.
  • Russ Back
    Russ Back almost 11 years
    The following doesn't output anything at all unfortunately: {{var customer.getFirstName()}}
  • Russ Back
    Russ Back almost 11 years
    @petergunn thanks for the update. That makes sense now as the Order model only has a getCustomerName() method, not a getCustomerFirstName() method. That being the case it looks like option b is the way I'll have to go
  • peter gunn
    peter gunn almost 11 years
    @RussBack Not quite, order model has the getCustomerFirstname() method (not getCustomerFirstName() ), it's used inside the getCustomerName() method. Try it, it's working for me.
  • simonthesorcerer
    simonthesorcerer almost 9 years
    order.getCustomerFirstname() doesn't work with guest checkout, order.getBillingAddress().getFirstname() does work with both