Customizing Email for pre-order on the basis of stock count

I have 4 variant for a single product. but all of them may not be available. some variants will have pre order option. i want to customize the email template that is when a user order an item with an available variant the email should show “thankyou for your purchase” and when a user purchase an item with a pre order variant it should show “thankyou for your pre order”. what i did right now is i have created meta fields for the product and set is pre order true for the variant which is not available. and edited the email template as below

{% assign delivery_method_types = delivery_agreements | map: ‘delivery_method_type’ | uniq %}
{% if delivery_method_types.size > 1 %}
{% assign has_split_cart = true %}
{% else %}
{% assign has_split_cart = false %}
{% endif %}

{% assign is_preorder = false %}

{% for line in order.line_items %}
{% if line.variant.metafields.custom.preorder == true %}
{% assign is_preorder = true %}
{% endif %}
{% endfor %}

{% capture email_title %}
{% if is_preorder %}
Thank you for your pre-order!
{% elsif has_pending_payment %}
Thank you for your order!
{% else %}
Thank you for your purchase!
{% endif %}
{% endcapture %}
{% capture email_body %}
{% if has_pending_payment %}
{% if buyer_action_required %}
You’ll get a confirmation email after completing your payment.
{% else %}
Your payment is being processed. You’ll get an email when your order is confirmed.
{% endif %}
{% else %}
{% if requires_shipping %}
{% case delivery_method %}
{% when ‘pick-up’ %}
You’ll receive an email when your order is ready for pickup.
{% when ‘local’ %}
Hi {{ customer.first_name }}, we’re getting your order ready for delivery.
{% else %}

      We're getting your order ready to be shipped. We will notify you when it has been sent.

  {% endcase %}

 {% if delivery_instructions != blank  %}
          <p><b>Delivery information:</b> {{ delivery_instructions }}</p>
        {% endif %}
       {% if consolidated_estimated_delivery_time %}
        {% if has_multiple_delivery_methods %}
          <h3 class="estimated_delivery__title">Estimated delivery</h3>
          <p>{{ consolidated_estimated_delivery_time }}</p>
        {% else %}
          <p>
            Estimated delivery <b>{{ consolidated_estimated_delivery_time }}</b>
          </p>
        {% endif %}
       {% endif %}
    {% endif %}
  {% endif %}

But this is not working as expected. still when a customer order a pre order product. the default email is sending which shows “Thankyou for your purchase”

Hi @djioff I’m @PaulNewton shopify-partner and I do theme/notification/liquid repairs.

You say “i have created meta fields for the product” but the code shows it’s checking variant metafields.
And email_title is never used etc.

Beyond that to spend more time diagnosing and to fix it you can reach out to me for customization services to.
CLICK my profile-pic or visit my profile on the forums
ALWAYS include context in new communications, e.g. reference urls, posts urls, etc

I’ve actually been in this exact situation before with mixed in-stock + preorder variants. Using a metafield is the right direction, but Shopify’s default email templating doesn’t read variant-level metafields unless you call them properly.

What worked for me was:

1. Adding a boolean metafield at the variant level (not product level).

2. In the template, wrapping the message in a simple Liquid check like:

{% if line_item.variant.metafields.custom.preorder == true %} Thank you for your pre-order {% else %} Thank you for your purchase {% endif %}

3. Then test it with a draft order to confirm it pulls the correct messaging.

Shopify’s notification emails are picky with metafields, so make sure you’re referencing the exact namespace + key. Once that’s right, it switches messaging perfectlyI can drop the exact Liquid snippet I used.