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!
Hey Community! As we jump into 2025, we want to give a big shout-out to all of you wh...
By JasonH Jan 7, 2025Hey Community! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024