Hi Community! I am trying to print a specific cart attribute named gift_note on my standard Packing Slip.
I have confirmed the attribute exists in the Order Admin > Additional Details.
I have tried two methods that are not returning data:
-
Direct access: {{ order.attributes.gift_note }} (Returned blank)
-
The Loop method:
{% for attribute in order.attributes %} {% if attribute.first == “gift_note” %} {{ attribute.last }} {% endif %} {% endfor %}
This is also returning nothing. Does anyone know why the Packing Slip order object might not be exposing these attributes, or if I am missing a syntax requirement?
The AI robot has suggested to me that cart attributes cannot be printed on the packing slip. If that is true, it suggested, there are two options: 1) merge the gift note with the order note, or 2) collect the gift note as an order metafield.
I don’t want to use option 1, because I use the order note for other things. Does anyone have experience collecting information as order metafields instead of attributes, and then printing those metafields on the standard packing slip?
It is actually very likely that your cart attributes code is failing simply because of a slight naming difference in Liquid. Before you go down complex route of setting you Metafields and automation, I strongly recommend you to try one small syntax tweak.
In many Shopify templates (especially Packing Slips and notifications), the object is often referenced as note_attributes rather than just attributes.
Try this Quick Fix First:
{% for attribute in order.note_attributes %}
{% if attribute.first == "gift_note" %}
<p><strong>Gift Note:</strong> {{ attribute.last }}</p>
{% endif %}
{% endfor %}
Note that the change from order.attributes to order.note_attributes everything else is the same**.**
Thank you for that insight! I tried that fix, but it’s still not printing the gift note on my packing slip.
Have you use the Shopify Flow for that? Or do you have experience with Shopify Flow, if I let you know the process? Because with the shopify flow we can resolve our issue effectively.
But how exactly would I use Flow to fix this? The customer’s gift note already shows up in “Additional Details” on the order, and I have inserted what appears to be correct code in the packing slip to print it. What exactly could Flow do to fix it?
Well, mainly this solution is via the Product Metafields but Shopify Flow will also use in it which is free to use.
So I am dividing this solution into 3 phases. And I hope you will implement it accordingly.
Phase 1: Create the metafield Definition:
- Go to Settings > Custom Data > Orders.
- Click Add Definition.
- Name: Gift Note
- Namespace and Key: custom.gift_note (Remember this, we need to use it in the code).
- Select type: Single line text (or Multi-line text).
- Save the metafield.
Phase 2: Create a Shopify Flow to transfer data:
This automation moves the data from attribute hidden spot to the Metafield visible spot.
- Open Shopify Flow app.
- Create a Workflow.
- Trigger: Select Order Created.
- **Condition (optional but recommended): **
Check if the attribute exists to avoid empty errors.
Criteria: order / note attributes / Names include “gift_note“.
- Action: Select Update Order Metafield.
Metafield namespace: custom
Metafield key: gift_note
Value: This is the tricky part. You need dynamic variable for the attribute value. In the value field, select Add Variable and look for order / NoteAttributes. You my need to use the liquid flow to grab the specific one. The code snippet shared below.
{% for attribute in order.noteAttributes %}{% if attribute.name == "gift_note" %}{{ attribute.value }}{% endif %}{% endfor %}
- In the last step Turn on the workflow.
Phase 3: Print it on the packing Slip
No that the data is stores in a metafield, printing is very reliable.
- Go to Settings > Shipping and delivery > Packing Slips > Edit.
- Find the spot where you want the note to appear.
- Paste the code that shared below.
{% if order.metafields.custom.gift_note != blank %}
<div class="gift-note-container" style="margin-top: 10px; padding: 10px; border: 1px solid black;">
<strong>Gift Note:</strong><br>
{{ order.metafields.custom.gift_note }}
</div>
{% endif %}
This is how you can print the specific cart attribute into your packaging slip.
I want to know from you whether the solution I provide help you out? If you facing any issue at any point then feel free to post it here in this thread.
It worked! I had to fiddle with the specifics of the code you wrote to get it to work properly, but the basic idea DOES work. The gift note is transfered to a metafield using Flow, and the metafield can then be printed on the packing slip. Thank you!
If I managed to help, then a like and solution will be helpful.