Fulfillment Liquid on Order template?

Highlighted
Shopify Partner
43 0 2

I have a client that is trying to get their order tracking numbers displayed to the customer on their order page (/account/orders/...)

 

I have looked up Shopify's docs but it seems like the fulfillment object is only available in email templates ...

 

Is there something I am missing? Has anyone been able to put the order tracking number on the order template before? 

0 Likes
Highlighted
Shopify Partner
43 0 2

Did a bit of research and I found out why this was not working for me ...

 

Shopify offers the ability for merchants to ship part of an order. This means that if someone ordered 5 different products and the merchant could only ship 3 today and 2 next week, there would be two different tracking numbers and two different URLs for tracking.

 

Because Shopify offers this, I had to use a work-around to get the tracking number and other info on the order page using a for loop. Here's what my code looks like.

 

<ul class="order-status">
  <li>Status: <span>{{ order.fulfillment_status_label }}</span></li>
  {% if order.fulfillment_status == 'fulfilled' %}
    <li>Tracking Number: 
      {% for line in order.line_items %}
        {% if line.fulfillment.tracking_number %}
          <span>{{ line.fulfillment.tracking_number }}</span>
        {% endif %}
      {% endfor %}
    </li>
    <li>Tracking Company: 
      {% for line in order.line_items %}
        {% if line.fulfillment.tracking_company %}
          <span>{{ line.fulfillment.tracking_company }}</span>
        {% endif %}
      {% endfor %}
    </li>
    <li>URL: 
      {% for line in order.line_items %}
        {% if line.fulfillment.tracking_url %}
          <a href="{{ line.fulfillment.tracking_url }}">Tracking URL</a>
        {% endif %}
      {% endfor %}
    </li>
  {% endif %}
</ul>

There might be a better way to code this, but it is working on my client's theme ATM.

 

Open to suggestions for improvement. Thanks!

 

 

0 Likes
Highlighted
New Member
1 0 0

Nice James, this is really helpful. Thank you!

 

Question for you. What's the best way to only display each tracking number once?

 

We never split our orders into multiple shipments, so each order only ever has one tracking number. But we also have orders with lots of line items, often 20 or more. In those cases the same tracking number is displayed 20  or times, which isn't great for UX.

0 Likes
Highlighted
New Member
2 0 0

Hi, did you ever figure this out? Trying to only display one tracking number per order as well.

0 Likes
Highlighted
New Member
1 0 0

This worked for me:

{% for line_item in order.line_items %}
     {% if forloop.first == true %}
<a href="{{ line_item.fulfillment.tracking_url }}" target="_blank">{{ line_item.fulfillment.tracking_number }}</a>
     {% endif %}
{% endfor %}
0 Likes
Highlighted
New Member
2 0 0
THANK YOU SO MUCH! This worked
0 Likes