Help edit liquid code with email template

Topic summary

A user is troubleshooting custom Liquid code added to their order confirmation email template. The code is designed to display special instructions when customers purchase specific services (service1 or service2).

Current behavior:

  • Works correctly when purchasing service1 alone
  • Works correctly when purchasing service2 alone
  • Works correctly when purchasing non-service products
  • Works correctly when service1 or service2 is the first item in cart

Problem identified:
The code fails when a regular product appears above service1 or service2 in the shopping cart—it incorrectly displays service instructions even when services were purchased.

The user has shared their Liquid code snippet that loops through line items and conditionally displays either email instructions or the standard email body based on product titles. They acknowledge not being a programmer and are seeking help to fix this logic issue.

Summarized with AI on November 17. AI used: claude-sonnet-4-5-20250929.

Hello, I am not a programmer but I have tried to edit the order confirmation template so that instructions are shown in the event that the customer purchases a service.
The code I have made works in several cases, but in some it doesn’t.
Ex:
It works when they buy service1
It works when they buy service2
It works when they buy other products that are not services
It works when they buy service1 or service2 if this is the first item
It does not work when a product appears in the shopping list above a service1 or service2 and shows else even though you have purchased the services.

{% for line in subtotal_line_items %}{% if line.product.title == 'service1' or line.product.title == 'service2' %}
            

{{ email_instructions}}

            {% else %}
            

{{ email_body }}

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

Thanks in advance.