Skip to main content
Question

Unable to add tracking number


Forum|alt.badge.img

Hello everyone,

 

I'm asking for your help with a question that seems fairly ‘simple’ but which I'm having absolutely no luck setting up and making work…


I would simply like to add my customers' order tracking numbers to a personalised email (to create an order delivery flow).
I tested the variable: {{ event.extra.fulfilments.0.tracking_number|default:‘’ }}

It ‘works’ but as my customers receive a gift card automatically (so there's no tracking number), the tracking displays nothing because it's trying to retrieve the gift card tracking number…


If I put: {{ event.extra.fulfilments.1.tracking_number|default:‘’ }} = It works. But on the other hand, for customers who order and don't have the gift card, the tracking number doesn't display anything…

 

If I put: {{ event.extra.fulfilments.tracking_number|default:‘’ }} = Strictly nothing is displayed…

 

Does anyone have a simple solution? I'm getting bored, stupidly, with a simple thing like that ahah.

 

Thanks a lot.

Did this topic or the replies in the thread help you find an answer to your question?

3 replies

MANSIR2094
Expert Problem Solver III
Forum|alt.badge.img+17
  • Expert Problem Solver III
  • 264 replies
  • March 11, 2025

Hey ​@Wiji77, welcome to the community. 

You're actually on the right track, but the issue comes from the fact that you're referencing specific indexes in the fulfilments array. Since some orders have a gift card and some don't, the tracking number's position in the array is not consistent.

The suggested approach is to loop through the fulfilments and find the first available tracking number. Try this:

liquid

Copy

Edit

{% for fulfilment in event.extra.fulfilments %}

{% if fulfilment.tracking_number != blank %}

{{ fulfilment.tracking_number }}

{% break %}

{% endif %}

{% endfor %}

This will go through all fulfilments in the order and display the first tracking number it finds, skipping empty ones (like the gift card). The {% break %} ensures it stops as soon as it finds one.

Let me know if this helps?


Forum|alt.badge.img
  • Author
  • Contributor I
  • 1 reply
  • March 12, 2025
MANSIR2094 wrote:

Hey ​@Wiji77, welcome to the community. 

You're actually on the right track, but the issue comes from the fact that you're referencing specific indexes in the fulfilments array. Since some orders have a gift card and some don't, the tracking number's position in the array is not consistent.

The suggested approach is to loop through the fulfilments and find the first available tracking number. Try this:

liquid

Copy

Edit

{% for fulfilment in event.extra.fulfilments %}

{% if fulfilment.tracking_number != blank %}

{{ fulfilment.tracking_number }}

{% break %}

{% endif %}

{% endfor %}

This will go through all fulfilments in the order and display the first tracking number it finds, skipping empty ones (like the gift card). The {% break %} ensures it stops as soon as it finds one.

Let me know if this helps?

 

Thank you very much for your feedback. It's really nice.
It's all quite new to me and I didn't quite understand (ahah sorry).
I have to put : 

{% for fulfilment in event.extra.fulfilments %}
{% if fulfilment.tracking_number != blank %}
{{ fulfilment.tracking_number }}
{% break %}
{% endif %}
{% endfor %}

In my email template, where do I want to display my tracking number?

Thanks again and sorry if my questions are a bit ‘simple’.


Byrne C
Community Manager
Forum|alt.badge.img+15
  • Community Manager
  • 127 replies
  • March 17, 2025

Hey ​@Wiji77,

Happy to step in for Mansir! You’d add that code into a text block or in the text section of a table/split, wherever you want the tracking number to be displayed. Mansir made what’s called a “for loop” which displays certain text for every item in an event (in this case, for every fulfillment in your fulfilled order metric). If an item in your event data has a tracking number, it’ll show that number, and then check to see if the next item has a tracking number. If that next item has a tracking number, it’ll show it, and so on. 

I’d recommend adding that to your template and checking to see if the tracking numbers display in the preview. If not, let us know, and we can work on another potential solution!

-Byrne