Help with Ship Confirmation Code

drewpul
New Member
1 0 0

Hi!

 

I added some code to the shipping confirmation email, but I get the error "Body html Liquid syntax error: Unexpected outer 'else' tag"

 

I checked my work many times and can't figure it out. Any ideas?

{% if fulfillment.item_count == item_count %}
{% capture shipment_name %}Your order is{% endcapture %}
{% elsif fulfillment.item_count > 1 %}
{% if fulfillment_status == 'fulfilled' %}
{% capture shipment_name %}The last items in your order are{% endcapture %}
{% else %}
{% capture shipment_name %}Some items in your order are{% endcapture %}
{% endif %}
{% else %}
{% if fulfillment_status == 'fulfilled' %}
{% capture shipment_name %}The last item in your order is{% endcapture %}
{% else %}
{% capture shipment_name %}One item in your order is{% endcapture %}
{% endif %}
{% endif %}

{% capture email_title %}{{ shipment_name }} on the way! {% endcapture %}
{% capture email_body %}
{% if shipping_method.title contains "First" %}
Your order is shipping via USPS First Class. You can expect to receive it within 10 - 14 business days.
{% else %}
{{ shipment_name }} on the way to you. It is coming via <b>{{ fulfillment.tracking_company }} </b> and has the tracking
number <b>{{ fulfillment.tracking_numbers }}</b> Please note: It could take up to 48 hours for your tracking link to
activate.
{% endif %}

{% if shipping_method.title contains "Media" %}
Please note: The tracking may indicate "pre-shipment" status for a period of time, but the shipment is indeed in
transit. USPS does not provide updates until closer to delivery with this ship method.
{% else %}

{% endif %}{% endcapture %}

{% capture email_emphasis %}Estimated delivery date: <strong>{{fulfillment.estimated_delivery_at | date: format: 'date'}}</strong>{% endcapture %}

<!DOCTYPE html>
<html lang="en">
  <head>
  <title>{{ email_title }}</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <meta name="viewport" content="width=device-width">
  <link rel="stylesheet" type="text/css" href="/assets/notifications/styles.css">
  <style>
    .button__cell { background: {{ shop.email_accent_color }}; }
    a, a:hover, a:active, a:visited { color: {{ shop.email_accent_color }}; }
  </style>
</head>

  <body>

    <table class="body">
      <tr>
        <td>
          <table class="header row">
  <tr>
    <td class="header__cell">
      <center>

        <table class="container">
          <tr>
            <td>

              <table class="row">
                <tr>
                  <td class="shop-name__cell">
                    {%- if shop.email_logo_url %}
                      <img src="{{shop.email_logo_url}}" alt="{{ shop.name }}" width="{{ shop.email_logo_width }}">
                    {%- else %}
                      <h1 class="shop-name__text">
                        <a href="{{shop.url}}">{{ shop.name }}</a>
                      </h1>
                    {%- endif %}
                  </td>

                    <td class="order-number__cell">
                      <span class="order-number__text">
                        Order {{ order_name }}
                      </span>
                    </td>
                </tr>
              </table>

            </td>
          </tr>
        </table>

      </center>
    </td>
  </tr>
</table>

          <table class="row content">
  <tr>
    <td class="content__cell">
      <center>
        <table class="container">
          <tr>
            <td>
              
            <h2>{{ email_title }}</h2>
                      <p>{{ email_body }}</p>
                      {% if fulfillment.estimated_delivery_at %}
                      <p>{{ email_emphasis }}</p>
                      {% endif %}
                      {% unless shipping_method.title contains "First" %}
                      {% if order_status_url %}
                      <table class="row actions">
                        <tr>
                          <td class="actions__cell">
                            <table class="button main-action-cell">
                              <tr>
                                {% if shipping_method.title contains "Media" %}
                                <td class="button__cell"><a
                                    href="https://store.wordonfire.org/apps/trackingmore?order={{ order.name }}&email={{ order.email }}"
                                    class="button__text">Track your order!</a>
                                </td>
                                {% else %}
                                <td class="button__cell"><a href="{{ fulfillment.tracking_urls }}"
                                    class="button__text">Track your order!</a>
                                </td>
                                {% endif %}
                              </tr>
                            </table>
                            {% if shop.url %}
                            <table class="link secondary-action-cell">
                              <tr>
                                <td class="link__cell"><a href="{{ order_status_url }}" class="link__text"><span
                                      class='or'>or</span> view
                                    your receipt</a></td>
                              </tr>
                            </table>
                            {% endif %}

                          </td>
                        </tr>
                      </table>

                      {% else %}
                      {% if shop.url %}
                      <table class="row actions">
                        <tr>
                          <td class="actions__cell">
                            <table class="button main-action-cell">
                              <tr>
                                <td class="button__cell"><a href="{{ shop.url }}" class="button__text">Visit our
                                    store</a></td>
                              </tr>
                            </table>
                          </td>
                        </tr>
                      </table>
                      {% endif %}
                      {% endif %}
                      {% endunless %}

                    </td>
                  </tr>
                </table>
              </center>
            </td>
          </tr>
        </table>

            {% else %}
              {% if shop.url %}
    <table class="row actions">
      <tr>
        <td class="actions__cell">
          <table class="button main-action-cell">
            <tr>
              <td class="button__cell"><a href="{{ shop.url }}" class="button__text">Visit our store</a></td>
            </tr>
          </table>
        </td>
      </tr>
    </table>
{% endif %}

            {% endif %}
            {% if fulfillment.tracking_numbers.size > 0 %}
  <p class="disclaimer__subtext">
    <br/>
    {% if fulfillment.tracking_numbers.size == 1 and fulfillment.tracking_company and fulfillment.tracking_url %}
      {{ fulfillment.tracking_company }} tracking number: <a href="{{ fulfillment.tracking_url }}">{{ fulfillment.tracking_numbers.first }}</a>
    {% elsif fulfillment.tracking_numbers.size == 1 %}
      Tracking number: {{ fulfillment.tracking_numbers.first }}
    {% else %}
      Tracking numbers:<br />
      {% for tracking_number in fulfillment.tracking_numbers %}
        {{ tracking_number }}<br />
      {% endfor %}
    {% endif %}
  </p>
{% endif %}


            </td>
          </tr>
        </table>
      </center>
    </td>
  </tr>
</table>
{% endunless %}

          <table class="row section">
  <tr>
    <td class="section__cell">
      <center>
        <table class="container">
          <tr>
            <td>
              <h3>Items in this shipment</h3>
            </td>
          </tr>
        </table>
        <table class="container">
          <tr>
            <td>
              
            
<table class="row">
  {% for line in fulfillment.fulfillment_line_items %}
  <tr class="order-list__item">
    <td class="order-list__item__cell">
      <table>
        <td>
          {% if line.line_item.image %}
            <img src="{{ line.line_item | img_url: 'compact_cropped' }}" align="left" width="60" height="60" class="order-list__product-image"/>
          {% endif %}
        </td>
        <td class="order-list__product-description-cell">
          {% if line.line_item.product.title %}	
            {% assign line_title = line.line_item.product.title %}	
          {% else %}	
            {% assign line_title = line.line_item.title %}	
          {% endif %}

          {% if line.quantity < line.line_item.quantity %}
            {% capture line_display %} {{ line.quantity }} of {{ line.line_item.quantity }} {% endcapture %}
          {% else %}
            {% assign line_display = line.line_item.quantity  %}
          {% endif %}

          <span class="order-list__item-title">{{ line_title }}&nbsp;&times;&nbsp;{{ line_display }}</span><br/>


          {% if line.line_item.selling_plan_allocation %}
            <span class="order-list__item-variant">{{ line.line_item.selling_plan_allocation.selling_plan.name }}</span><br/>
          {% endif %}

          {% if line.line_item.refunded_quantity > 0 %}
            <span class="order-list__item-refunded">Refunded</span>
          {% endif %}

          {% if line.line_item.discount_allocations %}
            {% for discount_allocation in line.line_item.discount_allocations %}
              {% if discount_allocation.discount_application.target_selection != 'all' %}
                <span class="order-list__item-discount-allocation">
                  <img src="{{ 'notifications/discounttag.png' | shopify_asset_url }}" width="18" height="18" class="discount-tag-icon" />
                  <span>
                    {{ discount_allocation.discount_application.title | upcase }}
                    (-{{ discount_allocation.amount | money }})
                  </span>
                </span>
              {% endif %}
            {% endfor %}
          {% endif %}
        </td>
      </table>
    </td>
  </tr>{% endfor %}
</table>


            </td>
          </tr>
        </table>
      </center>
    </td>
  </tr>
</table>

          <table class="row footer">
  <tr>
    <td class="footer__cell">
      <center>
        <table class="container">
          <tr>
            <td>
              
              <p class="disclaimer__subtext">If you have any questions, reply to this email or contact us at <a href="mailto:{{ shop.email }}">{{ shop.email }}</a><br>Would you like to return this order? <a
                          href="https://word-on-fire.returnly.com">Click Here.</a></p>
            </td>
          </tr>
        </table>
      </center>
    </td>
  </tr>
</table>

<img src="{{ 'notifications/spacer.png' | shopify_asset_url }}" class="spacer" height="1" />

        </td>
      </tr>
    </table>
  </body>
</html>


Reply 1 (1)
JoesIdeas
Shopify Expert
1426 127 384

It looks like this {% else %} doesn't have an associated {% if %} before it:

Screen Shot 2021-11-01 at 8.28.27 PM.jpg

 

I think the best way to debug this would be:

1) Copy all that code and put in a text editor, so you can see more of it and edit better than inside Shopify

2) Indent your code properly, for example:

{% if 1 == 1 %}
  {% if a == a %}
    this is properly indented
  {% endif %}
{% endif %}

{% if 1 == 1 %}
{% if a == a %}
this block is not indented, making it harder to track blocks when your code gets long
{% endif %}
{% endif %}

 

Once you have your code indented, it will be easy to track down the misaligned if / else blocks.

You could also copy all your current code to a text editor and save that, then in Shopify revert to the default template, and re-add in your customizations, being careful to make sure any mods you make don't disrupt the condition if / else logic.

Creator of Order Automator (auto tag orders / customers + auto fulfillment + more automations).
Creator of Shopify Analyzer (1st performance analysis tool for Shopify sites, free for the Shopify community).
Founder of Speed Boostr (Shopify optimization experts + app developers).
More apps: Theme Scientist (A/B testing), Tip Jar (add a tip button), File Optimizer (optimize CSS, JS, Liquid).