skip to Main Content

I am trying to create a simple IF statement to return a string of text in the email template that goes out to a customer when the order is fulfilled in Shopify.

I’m using this:

{% if order.metafields.custom.delivery_vehicle_type == 'Third-party Courier' %}
TEXT for courier
{% elsif order.metafields.custom.delivery_vehicle_type == 'Rigid Crane' %}
TEXT for RIGID CRANE
{% elsif order.metafields.custom.delivery_vehicle_type == 'Articulated Lorry (w/forklift)' %}
TEXT for MOFFET
{% else order.metafields.custom.delivery_vehicle_type == 'Articulated Lorry (w/Crane)' %}
TEXT for ARTIC CRANE
{% endif %}

But regardless of how I do this code, it only ever returns the ELSE section.

I have another code to check that the "custom.delivery_vehicle_type" does contain the correct information when selected in the metafield.

What am I doing wrong?

Any help will be great!!

TVM
D

2

Answers


  1. Chosen as BEST ANSWER

    Onkar - this is the image of the metafield from the order section This is the metafield information


  2. You need to check the if elsif else here

    you can pass the condition to else directly you need use elsif and you code become:

    {% assign vehical_type = '' %}
    {% if order.metafields.custom.delivery_vehicle_type == 'Third-party Courier' %}
      {% assign vehical_type = 'TEXT for courier' %}
    {% elsif order.metafields.custom.delivery_vehicle_type == 'Rigid Crane' %}
       {% assign vehical_type = 'TEXT for RIGID CRANE' %}
    {% elsif order.metafields.custom.delivery_vehicle_type == 'Articulated Lorry (w/forklift)' %}
       {% assign vehical_type = 'TEXT for MOFFET' %}
    {% else %}
        {% assign vehical_type = 'TEXT for ARTIC CRANE' %}
    {% endif %}
    

    and lastly use {{vehical_type }} like this where you want in bellow code.

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search