I have a custom customer/address attribute store_id, I want to add it in my Shipping Information: in sales email template, I know that currently it gets shipping address from


in function

 public function getShippingAddress()
    foreach ($this->getAddressesCollection() as $address) {
        if ($address->getAddressType()=='shipping' && !$address->isDeleted()) {
            return $address;
    return false;

Currently my Address look like this

Abdul Ghaffar, Street 10
Islamabad, Punjab, 44000
T: 123456789 

I am unable to find where this format is being created, I want to look address like

store_id -
Abdul Ghaffar, Street 10
Islamabad, Punjab, 44000
T: 123456789 

where store_id is my custom attribute.


Retrieved the value of this field and pass it as a param in the following function


  public function sendNewOrderEmail()
     /*Existing Code*/
     if ($this->getCustomerIsGuest()) {
            $templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_GUEST_TEMPLATE, $storeId);
            $customerId = Mage::getModel('customer/customer')->load($this->getCustomerId());
            $companyname = $customerId->getCompanyname();
            $storeID = $customerId->getStoreId();
        } else {
            $templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE, $storeId);
            $customerId = Mage::getModel('customer/customer')->load($this->getCustomerId());
            $customerName = $this->getCustomerName();
            $storeID = $customerId->getStoreId(); // fetch your custom attribute

          'order'        =>  $this,
          'billing'      =>  $this->getBillingAddress(),
          'payment_html' => $paymentBlockHtml,
          'storeid'  => $storeID 

After making this change. edit Transactional Email to include this param. Go to System > Transactional Emails > New Order Email and add like below :

 {{ var storeid }}
 {{var order.getShippingAddress.format('html')}}

hen this would get displayed in your Order Email in 'Shipping Address' Information right at the Start

P.S. I would advice you to override the core blocks instead of making changes in the core

| improve this answer | |
  • As you said, I am doing $storeID ='AG';'$mailer->setTemplateParams(array( 'order' => $this, 'billing' => $this->getBillingAddress(), 'payment_html' => $paymentBlockHtml, 'store_id' => $storeID ) );' and in template it is like '{{ var store_id }} {{var order.getShippingAddress().format('html')}}', I am getting in my email is "{{ var store_id }} Abdul Ghaffar, Street 10" – Abdul Ghaffar Apr 14 '16 at 13:32
  • this will not work until you remove space from ** {{ var storeid }}**, I mean it should be ** {{var storeid}}** – Abdul Ghaffar Apr 15 '16 at 9:01

if you want to change it create new phtml file and add your format this function is used many places. simply add you phtml like that in your email template..

 {{block type='core/template' area='frontend' template='email/order/shipping.phtml' order=$order}}
| improve this answer | |
  • 1
    This is also right, but I have solved my issue by @Manashvi birla answer – Abdul Ghaffar Apr 15 '16 at 9:02

You can change address format defined by default in the in app/code/core/Mage/Customer/config.xml. Go to System > Configuration > Customers > Customer Configuration > Address Templates and add the custom attribute where you want. Result should looks like this:

{{depend store_id}}Store ID{{var store_id}}{{/depend}}
{{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}} ....

You can find additional info here (pt. 3-5)

Note: The attribute should be present in the sales/order_address and sales/quote_address, in order to display correctly on all the stages.


Add attribute:

$installer = $this;


$this->addAttribute('customer_address', 'custom_store_id', array(
    'type' => 'text',
    'input' => 'text',
    'label' => 'Custom Store No#',
    'global' => 1,
    'visible' => 1,
    'required' => 0,
    'user_defined' => 1,
    'visible_on_front' => 1

    ->getAttribute('customer_address', 'custom_store_id')
    ->setData('used_in_forms', array('customer_register_address','customer_address_edit','adminhtml_customer_address'))

 * Adding Extra Column to sales_flat_order_address
 * to store the delivery instruction field
$sales_order_address = $installer->getTable('sales/order_address');
    ->addColumn($sales_order_address, 'custom_store_id', array(
        'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
        'comment' => 'Custom Store Id'

$sales_quote_address = $installer->getTable('sales/quote_address');
    ->addColumn($sales_quote_address, 'custom_store_id', array(
        'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
        'comment' => 'Custom Store Id'


Add fieldset:


Modify format:

Before {{depend custom_store_id}}Store ID{{var custom_store_id}} After

{{depend prefix}}{{var prefix}} {{/depend}}{{var firstname}} {{depend middlename}}{{var middlename}} {{/depend}}{{var lastname}}{{depend suffix}} {{var suffix}}{{/depend}}<br/>
{{depend company}}{{var company}}<br />{{/depend}}
{{if street1}}{{var street1}}<br />{{/if}}
{{depend street2}}{{var street2}}<br />{{/depend}}
{{depend street3}}{{var street3}}<br />{{/depend}}
{{depend street4}}{{var street4}}<br />{{/depend}}
{{if city}}{{var city}},  {{/if}}{{if region}}{{var region}}, {{/if}}{{if postcode}}{{var postcode}}{{/if}}<br/>
{{var country}}<br/>
{{depend telephone}}T: {{var telephone}}{{/depend}}
{{depend fax}}<br/>F: {{var fax}}{{/depend}}
{{depend vat_id}}<br/>VAT: {{var vat_id}}{{/depend}}

Get result: Result


Variables to the template come from the Mage_Core_Model_Email_Template::getProcessedTemplate():

 * Process email template code
 * @param   array $variables
 * @return  string
public function getProcessedTemplate(array $variables = array())
    $processor = $this->getTemplateFilter();

    if (!$this->_preprocessFlag) {
        $variables['this'] = $this;

    if (isset($variables['subscriber']) && ($variables['subscriber'] instanceof Mage_Newsletter_Model_Subscriber)) {

    // Apply design config so that all subsequent code will run within the context of the correct store

    // Populate the variables array with store, store info, logo, etc. variables
    $variables = $this->_addEmailVariables($variables, $processor->getStoreId());

        ->setTemplateProcessor(array($this, 'getTemplateByConfigPath'))
        ->setIncludeProcessor(array($this, 'getInclude'))

    try {
        // Filter the template text so that all HTML content will be present
        $result = $processor->filter($this->getTemplateText());
        // If the {{inlinecss file=""}} directive was included in the template, grab filename to use for inlining
        // Now that all HTML has been assembled, run email through CSS inlining process
        $processedResult = $this->getPreparedTemplateText($result);
    catch (Exception $e)   {
        throw $e;

    return $processedResult;

where the $processor->filter($this->getTemplateText()); calls callback functions (methods) one by one and replace a clause "{{...}}" by the result.

Address render comes from the Mage_Customer_Block_Address_Renderer_Default::render(). Customer attributes comes from the Mage_Customer_Helper_Address::getAttributes():

$attributes = Mage::helper('customer/address')->getAttributes();

So, if you get your attribute in the array from the method Mage_Customer_Helper_Address::getAttributes(), you can call it in the address template using this: {{var attributeName}}. The Mage_Core_Model_Email_Template_Filter::varDirective() method collects all variables and stores them in the array _templateVars. Method Varien_Filter_Template::_getVariable() finally replaces a variables from the _templateVars array.

| improve this answer | |
  • Will try this, but how orig_template_variables field is being set in core_email_template table – Abdul Ghaffar Apr 14 '16 at 13:42
  • @AbdulGhaffar I’ve updated my answer. I hope it will help you. – Siarhey Uchukhlebau Apr 15 '16 at 8:39
  • got it, my issue is solved, – Abdul Ghaffar Apr 15 '16 at 8:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.