Learning Liquid to send email notifications

Topic summary

A user is attempting to write Liquid code to conditionally display text in email notifications when customers order products containing “CardioChek” in the name. The code isn’t working as expected in sample emails.

The Problem:

  • Current code uses {% if line_items contains 'CardioChek' %} which checks the parent object incorrectly
  • Unclear whether Liquid logic executes in sample emails or requires actual test orders

The Solution Provided:

  • Need to loop through line items and check the title property of each item:
{% for item in line_items %}
  {% if item.title contains 'CardioChek' %}
    [message content]
    {% break %}
  {% endif %}
{% endfor %}

Additional Suggestions:

  • Consider using dedicated email marketing tools like Klaviyo for easier configuration of transactional email logic
  • One respondent promoted an AI email marketing tool (off-topic)

The issue remains open pending the original poster’s testing of the corrected code.

Summarized with AI on October 31. AI used: claude-sonnet-4-5-20250929.

Hi!

I am learning Liquid to use if to send a specific email notification to customers who order particular products.

I am not getting any errors, but when I send out the sample email, I don’t see the message even though it should show based on the the products in the sample order that are shown.

One question I have is Should the Liquid logic run using the products shown in the sample email, or do I need to actually create a test order?

The other question is Do you see any problem with this code. I want the text to display if any of the items on the invoice have the word “CardioChek” in them.

Thanks!

{% if line_items contains 'CardioChek' %} <p>If you've ordered a CardioChek Analyzer, but haven't ordered a starter kit or test strips, realize that you will need test strips to use your Analyzer. If you did not know this and need strips, we have planned for that. We sell a Starter Kit that includes 13 of the test strips that gives all the values your new analyzer provides: Overall Cholesterol, HDL, LDL, Triglycerides, Glucose, and Overall Cholesterol to HDL. The starter Kit also comes with 16 capillary tubes to move the blood from the finger to the unit and 16 lancets to puncture the skin. And it is available to you when you first buy your analyzer at a discount. If you order right away, we can ship the starter kit with your Analyzer. Here is the link to get your starter kit(s) <a href="https://bloodchekmedical.com/products/complete-cardiochek-starter-kit-only-99-with-analyzer-purchase">Click here for $99 Starter Kits</a> </p> {% endif %}
1 Like

Hey @RickBloodChek ,

First off, customising your email template based on orders is definitely possible directly through Liquid. But I do highly suggest using tools like Klaviyo for sending such transactional emails as the logics are much easier to configure over on that.

As far as your code is concerned, you will need to check against the correct element inside the line item object. In your case you’re checking if the parent object itself “contains” cardiocheck

Instead the code will go along the lines of

{% for item in line_items %}
  {% if item.title contains 'CardioChek' %}
    

Insert text here

    {% break %}
  {% endif %}
{% endfor %}

Let me know if you need any help tho - happy to help get you started in the right track!

Hey Rick, i know this isnt the solution your looking for but i just thought you might find this helpful to pump out emails a bit faster,

Im not selling anything btw just looking for a minute of your time.

I’m building an AI tool to make ecom email marketing effortless in a few clicks,

I would really appreciate it if you could help me see if this is something you would use

You’ll get early access at the end if you would like,

https://forms.gle/D6CmzwipLLzxuf8x8

Appreciate it! :raising_hands: