Personalized checkout and custom promotions with Shopify Scripts
My apologies as this may not be the correct forum location to post.
I've added the following code to include tracking information on the order History page. However, It is displaying the results for each item ordered. What should I change or add so that the results only display once?
{% for line_item in order.line_items %}
{% if line_item.fulfillment.tracking_numbers.size > 0 %}
<p class="disclaimer__subtext">
<br/>
{% if line_item.fulfillment.tracking_numbers.size == 1 and line_item.fulfillment.tracking_company and line_item.fulfillment.tracking_url %}
Your order has been shipped with {{ line_item.fulfillment.tracking_company }}! <br> Click below for shipping updates.
<a href="{{ line_item.fulfillment.tracking_url }}">{{ line_item.fulfillment.tracking_numbers.first }}</a>
{% elsif line_item.fulfillment.tracking_numbers.size == 1 %}
Tracking number: {{ line_item.fulfillment.tracking_numbers.first }}
{% else %}
Your order has been shipped with {{ line_item.fulfillment.tracking_company }}! <br> Click below for shipping updates.<br />
{% for tracking_number in line_item.fulfillment.tracking_numbers %}
{% if line_item.fulfillment.tracking_urls[forloop.index0] %}
<a href="{{shop.url}}/a/Ordertracking?nums={{ tracking_number }}">
{{ tracking_number }}
</a>
{% else %}
{{ tracking_number }}
{% endif %}
<br/>
{% endfor %}
{% endif %}
</p>
{% endif %}
{% endfor %}
Here's how it currently displays:
Solved! Go to the solution
This is an accepted solution.
Hi @Embellished1 , You can replace the below code with your code it will print the tracking information only once.
{% assign tracking_item = true %}
{% for line_item in order.line_items %}
{% if tracking_item %}
{% if line_item.fulfillment.tracking_numbers.size > 0 %}
<p class="disclaimer__subtext">
<br/>
{% if line_item.fulfillment.tracking_numbers.size == 1 and line_item.fulfillment.tracking_company and line_item.fulfillment.tracking_url %}
Your order has been shipped with {{ line_item.fulfillment.tracking_company }}! <br> Click below for shipping updates.
<a href="{{ line_item.fulfillment.tracking_url }}">{{ line_item.fulfillment.tracking_numbers.first }}</a>
{% elsif line_item.fulfillment.tracking_numbers.size == 1 %}
Tracking number: {{ line_item.fulfillment.tracking_numbers.first }}
{% else %}
Your order has been shipped with {{ line_item.fulfillment.tracking_company }}! <br> Click below for shipping updates.<br />
{% for tracking_number in line_item.fulfillment.tracking_numbers %}
{% if line_item.fulfillment.tracking_urls[forloop.index0] %}
<a href="{{shop.url}}/a/Ordertracking?nums={{ tracking_number }}">
{{ tracking_number }}
</a>
{% else %}
{{ tracking_number }}
{% endif %}
<br/>
{% endfor %}
{% endif %}
</p>
{% endif %}
{% assign tracking_item = false %}
{% break %}
{% endif %}
{% endfor %}
This is an accepted solution.
Hi @Embellished1 , You can replace the below code with your code it will print the tracking information only once.
{% assign tracking_item = true %}
{% for line_item in order.line_items %}
{% if tracking_item %}
{% if line_item.fulfillment.tracking_numbers.size > 0 %}
<p class="disclaimer__subtext">
<br/>
{% if line_item.fulfillment.tracking_numbers.size == 1 and line_item.fulfillment.tracking_company and line_item.fulfillment.tracking_url %}
Your order has been shipped with {{ line_item.fulfillment.tracking_company }}! <br> Click below for shipping updates.
<a href="{{ line_item.fulfillment.tracking_url }}">{{ line_item.fulfillment.tracking_numbers.first }}</a>
{% elsif line_item.fulfillment.tracking_numbers.size == 1 %}
Tracking number: {{ line_item.fulfillment.tracking_numbers.first }}
{% else %}
Your order has been shipped with {{ line_item.fulfillment.tracking_company }}! <br> Click below for shipping updates.<br />
{% for tracking_number in line_item.fulfillment.tracking_numbers %}
{% if line_item.fulfillment.tracking_urls[forloop.index0] %}
<a href="{{shop.url}}/a/Ordertracking?nums={{ tracking_number }}">
{{ tracking_number }}
</a>
{% else %}
{{ tracking_number }}
{% endif %}
<br/>
{% endfor %}
{% endif %}
</p>
{% endif %}
{% assign tracking_item = false %}
{% break %}
{% endif %}
{% endfor %}
This worked perfectly.
Thank you very much!
June brought summer energy to our community. Members jumped in with solutions, clicked ...
By JasonH Jun 5, 2025Learn how to build powerful custom workflows in Shopify Flow with expert guidance from ...
By Jacqui May 7, 2025Did You Know? May is named after Maia, the Roman goddess of growth and flourishing! ...
By JasonH May 2, 2025