Gettig all the tracking numbers associated with an order?

Hello,

how can I get all the trakcing IDs related to an order.

I tried:

{% if order.fulfillment_status == 'fulfilled' %}
- Tracking Number:
  {% for line in order.line_items %}
  {% if line.fulfillment.tracking_number %}
  {{ line.fulfillment.tracking_number }}
  {% endif %}
  {% endfor %}

- Tracking Company:
  {% for line in order.line_items %}
  {% if line.fulfillment.tracking_company %}
  {{ line.fulfillment.tracking_company }}
  {% endif %}
  {% endfor %}

- URL:
  {% for line in order.line_items %}
  {% if line.fulfillment.tracking_url %}
  Tracking URL
  {% endif %}
  {% endfor %}

{% else %}
Not shipped yet

{% endif %}

but it is rendering the same ID twice if there is 2 products in the order. How can I get all tracking numbers related to an order without looping through the items? Thanks!

You can try this::

{% if order.fulfillment_status == 'fulfilled' %}

{% for line in order.line_items %}

{% if line.fulfillment.tracking_number %}
- Tracking Number:
  {{ line.fulfillment.tracking_number }}

{% endif %}

{% if line.fulfillment.tracking_company %}
- Tracking Company:
  {{ line.fulfillment.tracking_company }}

{% endif %}

{% if line.fulfillment.tracking_url %}
- URL:
  {{ line.fulfillment.tracking_url }}

{% endif %}
{% endfor %}

{% else %}
Not shipped yet
{% endif %}

Hello thanks for the reply.

Unfortunately I can still see the same number twice in an order with 2 items:

{% if order.fulfillment_status == ‘fulfilled’ %}

{% for line in order.line_items %} {% if forloop.first == true %}

{% if line.fulfillment.tracking_number %}

  • Tracking Number: {{ line.fulfillment.tracking_number }}
  • {% endif %}

    {% if line.fulfillment.tracking_company %}

  • Tracking Company: {{ line.fulfillment.tracking_company }}
  • {% endif %}

    {% if line.fulfillment.tracking_url %}

  • URL: {{ line.fulfillment.tracking_url }}
  • {% endif %} {% endif %}{% endfor %}

    {% else %}
    Not shipped yet
    {% endif %}

    Try this version

    Hello,

    many thanks.

    Now if an order has 2 tracking codes it only displays one.

    I think the problem is that you cant loop through the codes themselves it seems.

    You always have to rely on the items.

    {% if order.fulfillment_status == 'fulfilled' %}
    
                               {% for line in order.line_items %}
                          
                      		    {% assign track_id = line.fulfillment.tracking_number %}
                          
                          			 {% if track_id != new_track_id %}
                                 
                                       {% if line.fulfillment.tracking_company %}
                                          
    
                                              {{ line.fulfillment.tracking_company }}
                                          
    
                                       {% endif %}
    
                                       {% if line.fulfillment.tracking_number %}
                                                                                 
                                              [{{ line.fulfillment.tracking_number }}](https://track.aftership.com/?tracking-numbers={{ line.fulfillment.tracking_number }})
                                          
    
                                       {% endif %}
                          
                     				     {% assign new_track_id = line.fulfillment.tracking_number %}
                          
                          			   {% else %}
                          
                           					{% break %}
    
      									{% endif %}
                                 
                           		{% endfor %}
    
                             {% else %}
                                 {{ 'customers.account.no_tracking_id' | t }}
                             {% endif %}
    
    1 Like