Customize your Shopify Email campaigns using Liquid

Liquid is Shopify's simple, easy-to-use programming language, and is the same programming language that themes from the Shopify Theme Store are built with.

You can use custom Liquid to enhance your Shopify Email messages by creating an entirely custom-coded email or by adding a custom Liquid section to a template. These options let you input custom Liquid or HTML.

You can use custom Liquid to display custom assets such as side-by-side images, custom buttons, custom sized images, and custom section sizes.

Considerations

Review the following considerations before you start adding custom Liquid to your Shopify Email messages:

  • The variables that you include in your code need to be supported by custom Liquid.
  • You can only use a desktop device to create a custom Liquid section.
  • The unsubscribe_link or unsubscribe_url variable is required in custom Liquid emails. If you've activated open tracking, then the open_tracking variable is also required. Learn more about adding required variables to your email.
  • The code that you enter has the following limits:
    • Maximum 50 kilobytes (KB) for custom Liquid sections.
    • Maximum 500 KB for custom-coded Liquid emails.

Liquid variables supported in custom Liquid

You can use supported variables to customize your Shopify email messages with Liquid. You can review the lists of supported Liquid variables for the following types of templates:

Liquid variables supported for all email templates

You can use the following variables to customize any of your Shopify email messages with Liquid.

Description of Shopify Email supported Liquid variables
VariableDescription
all_products
All of the products on your store.
customer.accepts_marketing
Returns true if the customer accepts marketing, and returns false if not.
customer.addresses
Returns all of the addresses associated with the customer.
customer.addresses_count
Returns the number of addresses associated with the customer.
customer.b2b?
Returns true if the customer is a B2B customer, and returns false if not.
customer.current_location
Returns the currently selected company location for the customer.
customer.default_address
Returns the customer's default address.
customer.email
Returns the customer's email address.
customer.first_name
Returns the customer's first name.
customer.has_account
Returns true if the customer's email is associated with a customer account, and returns false if not.
customer.has_avatar?
Returns true if the customer has an avatar associated with their account, and returns false if not.
customer.id
Returns the ID of the customer.
customer.last_name
Returns the customer's last name.
customer.last_order
Returns the last order placed by the customer, not including test orders.
customer.name
Returns the customer's full name.
customer.orders
Returns all of the orders that the customer has placed.
customer.orders_count
Returns the total number of orders that the customer has placed.
customer.payment_methods
Returns the customer's saved payment methods.
customer.phone
Returns the customer's phone number. The phone number populates only if the customer used a phone number at checkout, has opted in to SMS notifications, or if you've manually added it to their customer account.
customer.tags
Returns the tags associated with the customer.
customer.tax_exempt
Returns true if the customer is exempt from taxes, and returns false if not.
customer.total_spent
Returns the total amount that the customer has spent on all orders from your store.
email.*

This variable gives access to the following email properties:

  • subject displays the subject line of the email.
  • preview_text displays the preview text of the email.
  • open_tracking
    This variable gives access to the pre-formatted open tracking block. This variable is required if you create a custom-coded email and have activated open tracking.
    shop.*
    This variable gives access to the following shop properties:
  • name displays the shop name.
  • domain displays the shop primary domain.
  • url displays the shop URL.
  • shopify_domain displays the shop Shopify domain.
    • address displays the shop address, which gives access to the following address properties:
      • address1
      • address2
      • city
      • country
      • phone
      • province
      • zip
    unsubscribe_url
    This variable gives access to the raw unsubscribe URL, and can be customized. If you create a custom-coded email, then you're required to include the unsubscribe_url or unsubscribe_link variable.

    Liquid variables supported for abandoned checkout emails

    You can use the following variables to customize your abandoned checkout Shopify email messages with Liquid.

    The abandoned_checkout variable populates only if an email is part of an abandoned checkout marketing automation. Otherwise, the variable is null.

    Description of Shopify Email supported Liquid variables for abandoned browse, cart, and checkout
    VariableDescription
    abandoned_checkout.*

    This variable gives access to the following properties of an abandoned checkout:

    • url displays the URL of the abandoned checkout.
    • line_items displays the first five line items of the abandoned checkout. Additionally, each line_items object contains the following properties about each product:
      • components
      • image_url
      • product_title
      • variant_title
      • quantity
    • line_items.components displays the components of the abandoned checkout. Additionally, each components object contains the following properties about each component:
      • image_url
      • quantity
      • product_title
      • variant_title
    • remaining_products_count displays the remaining line items count, if there are more than five line items in the abandoned checkout.
    id
    (checkout ID)
    A unique ID of the checkout for internal use.
    shop
    Your Shopify store name.
    name
    The name of the abandoned checkout, also known as the checkout number.
    total_price
    The total price of the order (subtotal + shipping cost - shipping discount + tax).
    shipping_price

    The shipping price.

    Example: {{ shipping_price | money }}

    shipping_address
    The shipping address.
    billing_address
    The billing address.
    line_items
    A list of all line items in the abandoned checkout.
    unavailable_line_items
    A list of all line items in the abandoned checkout that aren't available.
    note
    The note that's attached to the abandoned checkout.
    landing_site

    The path of the landing site that the customer used. This is the first page that the customer accessed when they reached the store.

    Example: /products/great-product?ref=my-tracking-token

    landing_site_ref

    Extracts a reference parameter from the landing site. Reference parameters can be: ref, source, r.

    If the landing_site is /products/great-product?ref=my-tracking-token, then the landing_site_ref is my-tracking-token. You can perform a certain action if your reference parameter is equal to a certain value:

    {% if landing_site_ref == 'my-tracking-token' %}
    My action...
    {% endif %}
    referring_site

    The url of the referrer that brought the customer to your store.

    Example: https://www.google.com/?s=great+products

    created_at

    The date and time the customer created the checkout that they abandoned.

    closed_at

    The date and time when the checkout was closed.

    customer_locale
    The two or three-letter language code for customer's locale, optionally followed by a region modifier. For example,
    en
    ,
    en-CA
    item_count
    A sum of all the items' quantities.
    unique_gateways
    A list of unique payment providers available on the checkout.
    discount
    The discount applied to the cart or a line item in the abandoned checkout.
    discounts
    A list of discounts applied to the checkout.
    successfully_applied_discounts
    The discounts that were successfully applied to the checkout.
    discounts_amount

    The dollar amount of the discount applied by all discounts.

    Example: +$5.00

    discounts_savings

    The dollar amount of the savings caused by all discounts.

    Example: -$5.00

    buyer_accepts_marketing
    Returns
    true
    or
    false
    depending on whether the customer accepted marketing during the abandoned checkout.
    subtotal_line_items
    The line items that are used to calculate the subtotal price at checkout, excluding any tip line items.
    requires_shipping
    Returns
    true
    if there's at least one item in the checkout that requires shipping.
    subtotal_price
    The subtotal price of the line items at checkout.
    email
    The email associated with the abandoned checkout.
    shop_name
    The name of your store.
    tax_lines

    The taxes broken up by type of tax:

    {% for tax_line in tax_lines %}
    {{ tax_line.title }} ({{ tax_line.rate_percentage }}%) : {{ tax_line.price | money_with_currency  }}
    {% endfor %}
    tax_price
    The combined taxes of all the items in the checkout.
    attributes

    Any attributes that were attached to the abandoned checkout.

    Example: {{ attributes.gift-note }}

    shipping_method
    Information about the first shipping method available at checkout.
    shipping_methods
    The shipping methods available at checkout.
    free
    Returns
    true if the total price of the checkout is zero.
    free_shipping
    Returns
    true
    if the checkout doesn't require shipping, or if the price for shipping is zero.
    different_billing_address
    Returns
    true
    or
    false
    based on whether the shipping address is the same as the billing address.
    customer
    The customer object containing the attributes of the customer output.
    gift_cards
    The gift cards applied to the checkout.
    gift_cards_amount
    The amount of the checkout price that would be paid for by gift cards.
    transactions
    The transactions of the checkout.
    shareable_url
    The URL of the first product in the line items.
    shareable_title
    The product title of the first line item.
    total_tip
    The total tip that the customer added at checkout.
    discount_applications
    Describes why and how an item was discounted in the checkout.
    cart_level_discount_applications
    The cart-specific discount applications for the cart.
    currency
    The currency of the abandoned checkout.
    line_items_subtotal_price
    The sum of the prices of all the line items of the checkout, after any line item discounts are applied.

    Liquid variables for abandoned browse and abandoned cart emails

    The abandoned_visit.* variable populates only if an email is part of an abandoned cart or abandoned product browse marketing automation. Review the following properties that this variable gives access to.

    Description of Shopify Email supported Liquid variables
    VariableDescription
    abandoned_visit.*

    This variable gives access to the following properties of an abandoned cart or browse:

    • url displays the URL of the abandoned cart or browse.
    • products_added_to_cart displays the first five product line items added to the cart of the abandoned visit. Additionally, each products_added_to_cart object contains the following properties about each product:
      • title
      • image_url
      • variant_title
      • quantity
    • products_viewed displays the first five products viewed during the abandoned visit. Additionally, each products_viewed object contains the following properties about each product:
      • title
      • description
      • image_url
      • url
      • image_alt_text
    • remaining_cart_products_count displays the remaining line items count, if there are more than five line items in the abandoned checkout.

    Using required variables

    When you create a custom Liquid email, the variable unsubscribe_link or unsubscribe_url is required. If you've activated open tracking, then the open_tracking variable is also required.

    Although these variables can be inserted anywhere in the code for your email, the most common place to add them is in an email's footer section, such as in the following example:

    <div id="footer">{{ unsubscribe_link }} {{ open_tracking_block }}</div>

    Example of custom Liquid code

    You can add your custom Liquid or HTML in the code editor. The following code is an example of how you can add Liquid code to display your store name, a custom button, and a custom-sized image in an email message.

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>{{ shop.name }} Newsletter</title>
    </head>
    <body style="margin: 0; padding: 0; font-family: Arial, sans-serif; line-height: 1.5; color: #333333; background-color: #f5f5f5;">
        <table cellpadding="0" cellspacing="0" border="0" width="100%" style="background-color: #f5f5f5;">
            <tr>
                <td align="center" style="padding: 20px;">
                    <table cellpadding="0" cellspacing="0" border="0" width="600" style="background-color: #ffffff; border-radius: 4px; box-shadow: 0 2px 4px rgba(0,0,0,0.1);">
                        <!-- Header -->
                        <tr>
                            <td align="center" style="background-color: #4a6de5; padding: 30px 20px; color: #ffffff;">
                                <h1 style="margin: 0; font-size: 28px; font-weight: bold;">{{ shop.name }}</h1>
                                <p style="margin: 10px 0 0; font-size: 16px;">Your Book Journey with Us</p>
                            </td>
                        </tr>
    
                        <!-- Content -->
                        <tr>
                            <td style="padding: 30px 20px;">
                                <!-- Greeting Section -->
                                <table cellpadding="0" cellspacing="0" border="0" width="100%" style="margin-bottom: 30px;">
                                    <tr>
                                        <td>
                                            <h2 style="margin: 0 0 15px; font-size: 22px; color: #222222;">Hello {{ customer.name }}!</h2>
                                            <p style="margin: 0 0 15px; font-size: 15px;">We hope this email finds you well. We noticed you're from {{ customer.default_address.city }}.</p>
                                            {% if customer.email %}
                                                <p style="margin: 0 0 15px; font-size: 15px;">Your registered email is: {{ customer.email }}</p>
                                            {% endif %}
                                        </td>
                                    </tr>
                                </table>
    
                                <!-- Reading Journey Section -->
                                <table cellpadding="0" cellspacing="0" border="0" width="100%" style="margin-bottom: 30px;">
                                    <tr>
                                        <td>
                                            <h2 style="margin: 0 0 15px; font-size: 20px; color: #4a6de5;">Your Reading Journey</h2>
                                            <p style="margin: 0 0 15px; font-size: 15px;">Thank you for being a loyal customer! Here's a snapshot of your journey:</p>
                                            <p style="margin: 0 0 15px; font-size: 15px;">You purchased {{ customer.orders_count }} books with us.</p>
                                            {% if customer.last_order %}
                                                <p style="margin: 0 0 15px; font-size: 15px;"> You last read {{customer.last_order.line_items[0].title}}. Great choice! </p>
                                              {% endif %}
                                        </td>
                                    </tr>
                                </table>
    
                                <!-- Recommended Books Section -->
                                <table cellpadding="0" cellspacing="0" border="0" width="100%" style="margin-bottom: 30px;">
                                    <tr>
                                        <td>
                                            <h2 style="margin: 0 0 15px; font-size: 20px; color: #4a6de5;">Books You Might Love</h2>
                                            <p style="margin: 0 0 15px; font-size: 15px;">Based on your reading preferences, we've handpicked these titles just for you:</p>
    
                                            <table cellpadding="0" cellspacing="0" border="0" width="100%">
                                                <tr>
                                                    <td width="50%" style="padding-right: 10px;">
                                                        <table cellpadding="0" cellspacing="0" border="0" width="100%" style="background-color: #f9f9f9; border-radius: 4px; padding: 15px;">
                                                            <tr>
                                                                <td align="center">
                                                                    <!-- Image with proper email attributes -->
                                                                    <img src="https:{{ all_products['product-1-handle'] | image_url: width: 200 }}"
                                                                         alt="Product 1"
                                                                         width="200"
                                                                         height="200"
                                                                         style="display: block; border: 0; outline: none; text-decoration: none; -ms-interpolation-mode: bicubic;"
                                                                         title="Product 1"
                                                                         border="0">
                                                                    <h3 style="margin: 0 0 10px; font-size: 16px; color: #333333;">{{ all_products['product-1-handle'].title }}</h3>
                                                                    <p style="margin: 0 0 10px; font-size: 15px; color: #4a6de5;">${{ all_products['product-1-handle'].price }}</p>
                                                                    <a href="{{shop.domain}}{{ all_products['product-1-handle'].url }}" style="display: inline-block; background-color: #4a6de5; color: #ffffff; padding: 10px 20px; text-decoration: none; border-radius: 4px; font-size: 14px;">View Book</a>
                                                                </td>
                                                            </tr>
                                                        </table>
                                                    </td>
                                                    <td width="50%" style="padding-left: 10px;">
                                                        <table cellpadding="0" cellspacing="0" border="0" width="100%" style="background-color: #f9f9f9; border-radius: 4px; padding: 15px;">
                                                            <tr>
                                                                <td align="center">
                                                                    <!-- Image with proper email attributes -->
                                                                    <img src="https:{{ all_products['product-2-handle'] | image_url: width: 200 }}"
                                                                         alt="Product 2"
                                                                         width="200"
                                                                         height="200"
                                                                         style="display: block; border: 0; outline: none; text-decoration: none; -ms-interpolation-mode: bicubic;"
                                                                         title="Product 2"
                                                                         border="0">
                                                                    <h3 style="margin: 0 0 10px; font-size: 16px; color: #333333;">{{ all_products['product-2-handle'].title }}</h3>
                                                                    <p style="margin: 0 0 10px; font-size: 15px; color: #4a6de5;">${{ all_products['product-2-handle'].price }}</p>
                                                                    <a href="{{shop.domain}}{{ all_products['product-2-handle'].url }}" style="display: inline-block; background-color: #4a6de5; color: #ffffff; padding: 10px 20px; text-decoration: none; border-radius: 4px; font-size: 14px;">View Book</a>
                                                                </td>
                                                            </tr>
                                                        </table>
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                </table>
    
                                <!-- Book Club Section -->
                                <table cellpadding="0" cellspacing="0" border="0" width="100%" style="margin-bottom: 30px;">
                                    <tr>
                                        <td style="background-color: #f5f7ff; border-radius: 4px; padding: 25px; text-align: center;">
                                            <h2 style="margin: 0 0 15px; font-size: 18px; color: #333333;">This Month's Top Picks</h2>
                                            <p style="margin: 0 0 20px; font-size: 15px;">Discover what other readers are loving this month:</p>
                                            <a href="{{ shop.url }}/pages/book-club" style="display: inline-block; background-color: #4a6de5; color: #ffffff; padding: 10px 20px; text-decoration: none; border-radius: 4px; font-size: 14px;">Join Our Book Club</a>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
    
                        <!-- Footer -->
                        <tr>
                            <td style="background-color: #f2f2f2; padding: 30px 20px; text-align: center;">
                                <p style="margin: 0 0 15px; font-size: 15px;">Best regards,<br><strong>{{ shop.name }} Team</strong></p>
                                <p style="margin: 0 0 15px; font-size: 12px; color: #999999;">© {{ 'now' | date: '%Y' }} {{ shop.name }}. All rights reserved.</p>
                                <p style="margin: 0 0 15px; font-size: 12px;">{{ open_tracking_block }}</p>
                                <a href="{{ unsubscribe_url }}" style="color: #999999; font-size: 12px; text-decoration: underline;">{{ unsubscribe_link }}</a>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </body>
    </html>
    Can’t find the answers you’re looking for? We’re here to help.