Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
I have a problem where I need to send unique emails based on the stock level of an item. An item can be purchased when it is out of stock on the store I am working on, it just becomes made to order instead. I have looked at this documentation for guidance but I'm not sure if the line item stock level is available in an email template notification.
My attempt is to loop through the Line Items and keep a count of the total number of items and another count of how many are in stock and produce different messages by comparing the results.
When I have tried this code, I always get email 4 matter what. I'm not sure how to test a validity of the variable I'm using.
Here is my code:
{% assign line_item_count = 0 %}
{% assign inStockCount = 0 %}
{% for line in subtotal_line_items%}
{% assign line_item_count = line_item_count | plus: 1 %}
{% if line.variant.available == "true" %}
{% assign inStockCount = inStockCount | plus: 1 %}
{% endif %}
{% endfor %}
{% if inStockCount == count %}
{% comment %} All items are in stock {% endcomment %}
{{ email_1 }}
{% elsif inStockCount >= 1 and inStockCount < count>%}
{% comment %} There is at least one item out of stock but at least one item in stock {% endcomment %}
{% if shipping_address.country == "New Zealand"%}
{% comment %} The shipping address is in New Zealand with some items not in stock {% endcomment %}
{{ email_2 }}
{% else %}
{% comment %} The shipping address is not in New Zealand with some items not in stock {% endcomment %}
{{ email_3 }}
{% endif %}
{% else %}
{% comment %} All items are out of stock {% endcomment %}
{{ email_4 }}
{% endif %}
Hi, have you found a solution?
Hey Community 👋 Did you know that March 15th is National Everything You Think Is W...
By JasonH Apr 1, 2025Discover how to increase the efficiency of commerce operations with Shopify Academy's l...
By Jacqui Mar 26, 2025Shopify and our financial partners regularly review and update verification requiremen...
By Jacqui Mar 14, 2025