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! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024