Customizing the order confirmation email in Sitefinity Ecommerce

by
Venkata Koppaka
Feb 19, 2013

One of the popular PITS items we received was to have the ability to add custom fields to the confirmation email that is sent out after an order is placed in the Ecommerce module. Starting in Sitefinity 5.4, we have the ability to add custom fields to the email template. These fields are not restricted to just being custom fields on an order - you can add any field to the template such as a custom field from a product or a store setting or any custom message that your store might want to embed in each email. This post details on how to add custom order fields to the order confirmation email.

Now, before I go any further please read this documentation article which explains how to add custom fields to your orders and checkout process. This article assumes that you have already added custom fields to your order and are persisting them. Your preview page should look like the screenshot below after you made necessary changes –

To get started, open the page that has your checkout widget and edit the Order Confirmation Email Template

Once you are on the template editor, paste the snippet below to add GiftMessage (a custom field that was added to the order and persisted).

Note: By convention the tokens that are replaced in the email template begin and end with “%%” and are generally all upper case. So, in this example our custom “GiftMessage” token would be “%%GIFTMESSAGE%%”.

Now, add the following code in your Global.asax.cs file to register a custom formatter for Order Confirmation Email

Please note in the code above, inheriting from OrderConfirmationEmailTemplateFormatterBase is not mandatory. The class gives you a bunch of “helper” methods to make the formatting logic easier for you, the developer.

ReplaceTemplateValuesInTemplateBase method (part of OrderConfirmationEmailTemplateFormatterBase) returns a string notation of the formatted template which can be further modified, Lines 18 – 37 does exactly that and adds the GiftMessage string to the email.

5 comments

Is there documentation on the fields that can be used out-of-the-box with this syntax?

Svetla Yankova Apr 12, 2013

Hi Pierre,
We'll add this to the official docs as soon as possible, but the list I have is as following. There might be a few new ones that we need to add, as this is pre-Sitefinity 5.4. Hope this helps!

%%STORENAME%%

%%STOREURL%%

%%SHIPPINGMETHOD%%

%%TOTALQUANTITY%%

%%SUBTOTALDISPLAY%%

%%SHIPPINGTOTAL%%

%%TAX%%

%%TOTAL%%

%%/IFSHIPPABLE%%

%%IFSHIPPABLE%%

%%DISCOUNTS%%

%%DISCOUNTTITLE%%

%%DISCOUNTSAVINGSAMOUNT%%

%%DISCOUNTS%%

%%PRODUCTS%%

%%PRODUCTSKU%%

%%PRODUCTTITLE%%

%%PRODUCTOPTIONS%%

%%PRODUCTPRICE%%

%%PRODUCTQUANTITY%%

%%DETAILTOTAL%%

%%CREDITCARDTYPE%%

%%CREDITCARDNUMBER%%

%%CREDITCARDTYPE%%

%%CREDITCARDNUMBER%%

%%BILLINGADDRESS1%%

%%BILLINGADDRESS2%%

%%BILLINGCITY%%

%%BILLINGCOMPANYNAME%%

%%BILLINGCOUNTRY%%

%%BILLINGEMAIL%%

%%BILLINGFIRSTNAME%%

%%BILLINGLASTNAME%%

%%BILLINGPHONE%%

%%BILLINGSTATE%%

%%BILLINGPOSTAL%%

%%SHIPPINGADDRESS1%%

%%SHIPPINGADDRESS2%%

%%SHIPPINGCITY%%

%%SHIPPINGCOMPANYNAME%%

%%SHIPPINGCOUNTRY%%

%%SHIPPINGEMAIL%%

%%SHIPPINGFIRSTNAME%%

%%SHIPPINGLASTNAME%%

%%SHIPPINGPHONE%%

%%SHIPPINGSTATE%%

%%SHIPPINGPOSTAL%%

%%ORDERNUMBER%%

%%PLACEDON%%

Surbhi Sep 24, 2013

Hi,
How do I get the existing variables in code behind?
I want to replace the %%productprice%% variable value to some other value which would be based on some calculations.

Please help!

Thanks,
Surbhi Agarwal

James Oct 24, 2013

How do I show an Item's custom field in the email?

Dominic Apr 15, 2016

My variable %%BILLINGLASTNAME%% is not showing the complete last name of the user.

The last name should be : "Lecours Brewster" and it only shows "Lecours". It seems like the last name is truncated on the space.

Webinars

Tools

Progress, Telerik, Sitefinity and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries.