How to only display tracking information ONCE on order history page

Solved

How to only display tracking information ONCE on order history page

Embellished1
Visitor
3 0 1

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:

 

Screenshot 2024-06-30 000852.png

Accepted Solution (1)

Rishihuptech
Shopify Partner
616 113 125

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 %}
If you found this response helpful, please do like and accept the solution. Thanks!
Need support with Customizing your Shopify store?
Feel free to contact me at info@huptechweb.com or Visit our website Huptech Web.
Instant Shortcode Builder: Integrate customizable UI features anywhere in your store - No coding knowledge required

View solution in original post

Replies 2 (2)

Rishihuptech
Shopify Partner
616 113 125

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 %}
If you found this response helpful, please do like and accept the solution. Thanks!
Need support with Customizing your Shopify store?
Feel free to contact me at info@huptechweb.com or Visit our website Huptech Web.
Instant Shortcode Builder: Integrate customizable UI features anywhere in your store - No coding knowledge required
Embellished1
Visitor
3 0 1

This worked perfectly. 

Thank you very much!