Using variables for notifications and scripts
You can use variables in your email notifications and Thank you page. Variables allow the output of dynamic content depending on the content of the orders or the attributes of a customer.
This guide outlines the variables that can be implemented in Recharge. For general information, refer to the Notifications article.
Before you start
- This documentation is meant to be used as a reference in order for you, your team, or a recommended third-party developer to accomplish. Customizations are not supported by Recharge's support team, as per the Recharge design and integration policy.
- Recharge is a Python app and uses Jinja2, the Python Template Engine. You can use this list of built-in features.
- If you need more flexibility or do not have the technical resources to modify your notifications, we recommend using a compatible Communication and Email/SMS marketing third-party integration. Take a look at the apps and integrations.
Standard variables for notifications and scripts
{{email}}
.
Variable |
Shopify Checkout Integration |
Recharge Checkout on BigCommerce |
first_name |
Yes | Yes |
last_name |
Yes | Yes |
|
Yes | Yes |
order_number Only created after an order is processed. Cannot be used in Upcoming Order notifications. |
Yes | Yes |
order_name Only created after an order is processed. Cannot be used in Upcoming Order notifications. |
No | No |
id Order id |
Yes | No |
subtotal_price |
Yes | Yes |
total_price |
Yes | Yes |
total_discounts The total amount discounted from an order. |
Yes | Yes |
discount |
Yes | Yes |
discount_code This will store the actual discount string for your discount. For example, HALFOFF. |
Yes | Yes |
discount_type |
Yes | Yes |
charge_date |
Yes | Yes |
total_tax |
No | Yes |
tax |
No | Yes |
tax_lines.title |
No | Yes |
tax_lines.price |
No | Yes |
total_shipping |
Yes | Yes |
shipping |
No | No |
browser_ip |
Yes | No |
ip_address |
Yes | No |
amount |
Yes | Yes |
customer Displays Recharge customer id and store id only |
Yes | Yes |
total_weight
|
No | Yes |
sepa_debit_last4
|
No | Yes |
billing_address |
Yes | Yes |
shipping_address shipping_address.first_name shipping_address.last_name shipping_address.address1 shipping_address.address2 shipping_address.city shipping_address.zip shipping_address.province shipping_address.phone shipping_address.company |
Yes | Yes |
shipping_lines |
No | Yes |
out_of_stock_items |
Yes |
Yes
|
refund_amount Variable used in the Refund notification. |
No | Yes |
attributes.attribute_name This will display the cart attribute. The attribute_name portion should reflect the name of your attribute and is case-sensitive. The attribute_name must be enclosed in single quotes inside square brackets [ ] in order to function correctly: ['attribute_name'] |
Yes |
No
|
total_duties This is only available for the Subscription activation notification. |
Yes | No |
Use these variables like the following example:
<td>
<span>{{discount_code}}</span>
</td>
<td>
<span>{{total_discounts | amount_with_currency(charge_currency, display_currency_code=False)}}
</span>
</td>
Variables for notification templates only
The following variables can only be used in the notification templates and cannot be used on the Thank You page.
Variable |
Shopify Checkout Integration |
Recharge Checkout on BigCommerce |
link subscription_url login_url These magic links direct customers to their customer portal. |
Yes | Yes |
billing_link This magic link directs customers to their Billing Information page in the customer portal. |
Yes | Yes |
delivery_schedule_link This magic link directs customers to the Delivery Schedule page in the customer portal. |
Yes | Yes |
item.previous_price California auto-renewal law requires that customers are notified between 3 and 21 days before a free gift, trial, promotional terms or discounted price expires. This variable will trigger the Upcoming Charge notification to include a message indicating there has been a price change since the last charge. Customers are notified for all price changes, including manual pricing adjustments, or price changes made through a workflow. |
Yes | Yes |
amount_with_currency(charge_currency) See variables for multi-currency configuration for specifics on how to use. |
Yes | No |
shop_url shop_name shop_address |
Yes | Yes |
Use these variables like the following example:
{% if shop_email %}
<p>Please email us <a href="mailto:{{ shop_email }}" about="_blank" rel="noopener noreferrer">here</a> if you have any questions about your subscription.</p>
{% endif %}
Variables requiring a loop
There are other variables you can use that are related to the items in the purchase. However, to use these types of variables, you must go through line_items within a loop.
Variable |
Shopify Checkout Integration |
Recharge Checkout on BigCommerce |
fulfillment_service |
No | No |
grams |
No | Yes |
name |
Yes | Yes |
price |
Yes | Yes |
product_id |
Yes | Yes |
product_title |
Yes | Yes |
quantity |
Yes | Yes |
sku |
Yes | Yes |
title |
Yes | Yes |
variant_id |
Yes | Yes |
variant_title |
Yes | Yes |
Use these variables within a loop like the following example:
{% for item in line_items %} {{ item.product_title }} {% endfor %}
Note: The conditional IF structure causes the shipping interval to be printed only if it's a subscription product.
Displaying line item properties
{% for item in line_items %}
{% if item.properties %}
{% for p in item.properties %}
{{ p }}:{{ item.properties[p] }}
{% endfor %}
{% endif %}
{% endfor %}
Variables for multi-currency configuration
These variables can be used in the subscription activation, upcoming charge, advanced notice upcoming renewal charge (1+ year confirmation), and refund confirmation notifications to show or hide the currency country code.
To implement the multi-currency variables, replace insert price variable
with "subtotal_price" or "total_price" or "total_discounts".
-
To show the currency code: {{ insert price variable | amount_with_currency(charge_currency, display_currency_code=True) }}.
-
For example
{{ total_price | amount_with_currency(charge_currency, display_currency_code=True) }}
-
For example
- To hide the currency country code: {{insert price variable | amount_with_currency(charge_currency) }}.
- For example
{{ total_price |amount_with_currency(charge_currency) }}
- For example
Variables within additional scripts and trackers
- Merchants using the Shopify Checkout Integration do not have access to the Checkout settings in Recharge, as the checkout is handled entirely by Shopify. Refer to Shopify's guide to customize the order status page to learn more about adding additional scripts.
- Merchants using the BigCommerce Checkout Integration add scripts directly in BigCommerce using the Script Manager.
You can use scripts containing variables on the Thank you page.
- Click Storefront in your merchant portal and select Checkout.
- Scroll down to the Thank you page section and add the code in the Add additional scripts and trackers text box.
- (Optional) To test render the additional scripts and trackers section for a specific order, click Preview.
- Click Save once finished.
Use a "for loop" for line items
You can get variables on the item level as well using a for loop like:
{% for item in line_items %}{{item.sku}}, {% endfor %}
Render scripts on first-load
If you want the scripts to only render the first time the page is accessed, you can use the following lines of code.
{% if first_time_load %} {% endif %}
show_scripts=true
to the checkout URL to force the script to show for debugging purposes.Variables for SMS
SMS variables can be used with RechargeSMS or passwordless login to customize SMS notifications.
Note the following limitations when using SMS variables:
- SMS notifications have a 160-character limit.
- Each SMS variable, with the exception of access_code, counts as 30 characters towards the 160-character limit.
- Variables may be cut off when rendering a variable with a character value longer than the 30-character allocation. To ensure customer names are not cut off, we suggest using first_name and last_name as separate variables.
Variable |
Description |
Shopify Checkout Integration |
shop_email | Your shop email | Yes |
store_name | Your shop name | Yes |
customer_name | The customer's full name | Yes |
first_name | The customer's first name only | Yes |
last_name | The customer's last name only | Yes |
access_code |
The customer's four-digit access code Note: This variable can only be used with passwordless login and is not available for RechargeSMS notifications. |
Yes |
Use these variables like the following example:
Hi {{customer_name}}, just wanted to let you know your order will be processing soon.
To change your order, reply to this message with 'Modify Order' - {{shop_name}}
Common issues
Shopify
When copying over the Liquid code from the Shopify checkout, there are some key differences in the variables used in Recharge.
- When looping through items make sure it is
{% for line_item in line_items %}
not{% for line_item in order.line_items %}
. - Shopify only allows one discount per order so you can remove all the discount loops. Use
{{ discount_code }}
instead. - Remove all filters like
| money_without_currency
. - Note that the liquid directive "contains" doesn’t work in Recharge notifications.
{% if item.product_title contains "Auto Renew" %}
The alternative is using the "in" directive
{% if "Auto Renew" in item.product_title %}