Customizing Shopify Order Confirmation Emails with Line Item Attributes

How to use line item properties for precise email content

Rob Johnson

By Rob Johnson

Wed Oct 02 2024

#shopify

Shopify's order confirmation emails are a crucial touchpoint in your customer journey. While the standard template provides essential information, you can significantly enhance it by incorporating line item attributes. This allows for more personalized and relevant communication, improving customer satisfaction and potentially driving repeat business.

Accessing Line Item Attributes

Within Shopify's email templates, you can access a wealth of information about each item in an order. This includes details like:

  • Product title: line.title
  • Variant details: line.variant.title
  • SKU: line.sku
  • Price: line.price
  • Quantity: line.quantity
  • Properties: line.properties (This is where custom attributes reside)

You can utilize these variables within the email template's Liquid code to display specific information or create conditional logic.

Customizing Your Email with Line Item Properties

Let's say you want to include specific care instructions for certain products in your order confirmation email. You can achieve this by adding a custom property to those products within your Shopify admin. For instance, a "Care Instructions" property could be added to a "Silk Scarf" product with the value "Hand wash only."

In your email template, you can then use Liquid code to display these instructions conditionally:

{% for line in subtotal_line_items %}
  {% if line.properties.Care Instructions %}
    <p>Special care instructions for {{ line.title }}: {{ line.properties.Care Instructions }}</p>
  {% endif %}
{% endfor %}

This code iterates through each line item in the order and checks if the "Care Instructions" property exists. If it does, it displays a paragraph with the product title and the corresponding care instructions.

Example: Display Logic for Personalized Recommendations

You can further leverage line item attributes for dynamic content. Let's imagine you want to recommend related products based on items in the order.

{% for line in subtotal_line_items %}
  {% if line.product.product_type == 'T-Shirt' %}
    <p>Looking for more awesome T-shirts? Check out our new arrivals <a href="#">here</a>!</p>
  {% endif %}
{% endfor %}

In this example, the code checks if a line item's product type is "T-Shirt." If it is, it displays a recommendation to browse other T-shirts.

You can also check to see if the line item is a subscription item via

{% if line.selling_plan_allocation %}
  <span>This is a subscription item</span>
{% endif %}

Conclusion

By utilizing line item attributes in your Shopify order confirmation emails, you can create a more personalized and informative experience for your customers. This level of customization can lead to increased engagement, satisfaction, and ultimately, drive more sales.

References

Customize your Shopify Email campaigns using Liquid

Data contained at the line item level (line.).

{
  "id": 487817672276298554,
  "title": "Aviator sunglasses",
  "price": "89.99",
  "line_price": "89.99",
  "quantity": 1,
  "current_quantity": 0,
  "item_updates": [],
  "aggregated_update": null,
  "sku": "SKU2006-001",
  "grams": 100,
  "properties": [],
  "vendor": null,
  "requires_shipping": true,
  "applied_discounts": [],
  "tax_lines": [],
  "taxable": true,
  "gift_card": false,
  "variant_id": null,
  "variant": null,
  "url": null,
  "product": {
    "id": 788032119674292922,
    "title": "Aviator sunglasses",
    "body_html": "An example T-Shirt",
    "vendor": "Acme",
    "product_type": "Shirts",
    "created_at": null,
    "handle": "example-t-shirt",
    "updated_at": "2024-10-02T14:47:43-07:00",
    "published_at": "2024-10-02T14:47:43-07:00",
    "template_suffix": null,
    "published_scope": "web",
    "tags": "example, mens, t-shirt",
    "image": null,
    "admin_graphql_api_id": "gid:\/\/shopify\/Product\/788032119674292922",
    "variants": [
      {
        "id": 642667041472713922,
        "product_id": 788032119674292922,
        "title": "Small",
        "price": "19.99",
        "position": 1,
        "inventory_policy": "deny",
        "compare_at_price": "24.99",
        "option1": "Small",
        "option2": null,
        "option3": null,
        "created_at": "2024-09-30T14:47:43-07:00",
        "updated_at": "2024-10-01T14:47:43-07:00",
        "taxable": true,
        "barcode": null,
        "fulfillment_service": "manual",
        "grams": 0,
        "inventory_management": null,
        "requires_shipping": true,
        "sku": null,
        "weight": 0.0,
        "weight_unit": "lb",
        "inventory_quantity": 75,
        "old_inventory_quantity": 75,
        "tax_code": "",
        "admin_graphql_api_id": "gid:\/\/shopify\/ProductVariant\/642667041472713922",
        "image_id": null
      },
      {
        "id": 757650484644203962,
        "product_id": 788032119674292922,
        "title": "Medium",
        "price": "19.99",
        "position": 2,
        "inventory_policy": "deny",
        "compare_at_price": "24.99",
        "option1": "Medium",
        "option2": null,
        "option3": null,
        "created_at": "2024-09-30T14:47:43-07:00",
        "updated_at": "2024-10-02T14:47:43-07:00",
        "taxable": true,
        "barcode": null,
        "fulfillment_service": "manual",
        "grams": 0,
        "inventory_management": null,
        "requires_shipping": true,
        "sku": null,
        "weight": 0.0,
        "weight_unit": "lb",
        "inventory_quantity": 50,
        "old_inventory_quantity": 50,
        "tax_code": "",
        "admin_graphql_api_id": "gid:\/\/shopify\/ProductVariant\/757650484644203962",
        "image_id": null
      }
    ],
    "options": [
      {
        "id": 527050010214937811,
        "product_id": 788032119674292922,
        "name": "Title",
        "position": 1,
        "values": [
          "Small",
          "Medium"
        ]
      }
    ],
    "images": []
  },
  "fulfillment": null
}