Gettig all the tracking numbers associated with an order?

Shop2000
Excursionist
12 0 2

Hello,

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

I tried:

{% 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>
{% 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!

0 Likes
MandasaTech
Shopify Expert
39 4 10

You can try this::

 

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

{% for line in order.line_items %}

{% if line.fulfillment.tracking_number %}
<li>Tracking Number:
<span>{{ line.fulfillment.tracking_number }}</span>
</li>
{% endif %}

{% if line.fulfillment.tracking_company %}
<li>Tracking Company:
<span>{{ line.fulfillment.tracking_company }}</span>
</li>
{% endif %}

{% if line.fulfillment.tracking_url %}
<li>URL:
<span>{{ line.fulfillment.tracking_url }}</span>
</li>
{% endif %}
{% endfor %}

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

 

Want to modify or custom changes on store for affordable price?
Hire us - https://experts.shopify.com/mandasa-technologies
Website: http://www.mandasa.in/
Email: info@mandasa.in
If helpful then please Like and Accept Solution.
0 Likes
Shop2000
Excursionist
12 0 2

Hello thanks for the reply.

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

scrnli_7_12_2021_2-31-24 PM.png

0 Likes
MandasaTech
Shopify Expert
39 4 10

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

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

{% if line.fulfillment.tracking_number %}
<li>Tracking Number:
<span>{{ line.fulfillment.tracking_number }}</span>
</li>
{% endif %}

{% if line.fulfillment.tracking_company %}
<li>Tracking Company:
<span>{{ line.fulfillment.tracking_company }}</span>
</li>
{% endif %}

{% if line.fulfillment.tracking_url %}
<li>URL:
<span>{{ line.fulfillment.tracking_url }}</span>
</li>
{% endif %}
{% endif %}{% endfor %}

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


Try this version

Want to modify or custom changes on store for affordable price?
Hire us - https://experts.shopify.com/mandasa-technologies
Website: http://www.mandasa.in/
Email: info@mandasa.in
If helpful then please Like and Accept Solution.
0 Likes
Shop2000
Excursionist
12 0 2

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.

0 Likes
Shop2000
Excursionist
12 0 2
  {% 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 %}
                                      <div>
                                          <span>{{ line.fulfillment.tracking_company }}</span>
                                      </div>
                                   {% endif %}


                                   {% if line.fulfillment.tracking_number %}
                                       <div>                                      
                                          <span><a href="https://track.aftership.com/?tracking-numbers={{ line.fulfillment.tracking_number }}" target="_blank">{{ line.fulfillment.tracking_number }}</a></span>
                                      </div>
                                   {% endif %}
                      
                 				     {% assign new_track_id = line.fulfillment.tracking_number %}
                      
                      			   {% else %}
                      
                       					{% break %}

  									{% endif %}
                             
                       		{% endfor %}

                         {% else %}
                             {{ 'customers.account.no_tracking_id' | t }}
                         {% endif %}