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?

2 replies

MANSIR2094
Problem Solver IV
Forum|alt.badge.img+17
  • Problem Solver IV
  • 262 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’.


Reply