Magento 1.7 Email Templates – How to Customize Shipping Address Variable in Transactional Email

addresscustomeremailemail-templatesmagento-1.7

I am customizing Magento's transactional emails and am trying to remove the Telephone/Fax from displaying in the email as they are displaying as:

T:-
F:-

The transactional mail template for new orders in the CMS is calling:

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

Which is defined in the top of the (cms based) email template as:

"var order.getShippingAddress().format('html')":"Shipping Address"

I don't quite understand what the purpose of this 'variable' definition is, but I also see no reference to this in the sales.xml file.

Does anyone know how to adjust this html? Is there a clear methodology for finding where things are defined/pulled from in Magento? I am clearly confused coming from working primarily with WordPress theming.

Apologies for the endless string of transactional email questions. Hopefully this will help build the beta stack exchange as a valuable resource 🙂

Best Answer

Actually the variables defined at the top of the email are 'injected' when the template is called. In this case it's the order object.

If you check out the file app/code/core/Mage/Sales/Model/Order.php you can find around the line 948 the method getShippingAddress. This is the actual function you're referencing here.

Now for the format('html') part, this is where you can actually start making some changes. And the best part is, no coding is required.

Go to your backend System > Configuration > Customer configuration > Addresslayout and look for the field HTML. By default it will look like this:

{{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}}{{/if}}
{{depend street2}}{{var street2}}{{/depend}}
{{depend street3}}{{var street3}}<br />{{/depend}}
{{depend street4}}{{var street4}}<br />{{/depend}}
{{if postcode}}{{var postcode}}{{/if}} {{if city}}{{var city}}  {{/if}}{{if region}}{{var region}} {{/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}}

As you can see removing telephone and fax altogether is just a matter of deleting the last 2 lines before the VAT line.

Related Topic