Re: How to make a specific cart attribute appear on the packing slip

Solved

How to make a specific cart attribute appear on the packing slip

John_jmk
Excursionist
22 0 5

Hi all

Hope all of you stay well and safe.

I entered an additional cart attribute in the cart template liquid as below:

-------------------

<div>
<input type="hidden" name="attributes[Requested a spatula?]" value="No">
<input type="checkbox" name="attributes[Requested a spatula?]" value="Yes"{% if cart.attributes["Requested a spatula?"] == "Yes" %} checked{% endif %}>
<label style="padding-left: 3px; display:inline; float:none">I'd like a reusable skincare spatula to keep my pots of creams clean and fresh.</label>

</div>

-------------------

And with this code in, the Shopify order page looks like below:

ADDITIONAL DETAILS

created_at

1xxxxxxxx

mc_cid
acxxxxx

Requested a spatula?
Yes

 

Also, I entered the following code in the packing slip template, wanting the 3rd attribute "Requested a spatula" section to appear:

{% for attribute in attributes %}
*{{ attribute | first }} {{ attribute | last }}<br>
{% endfor %}

 

However, all information including mailchimp tracking info from the 'Additional Details' section appear on the packing slip.

Is there any way that I can make a specific attribute/s only appear on the packing slip? In this case, the 'Requested a spatula?' part only.

 

Any help will be greatly appreciated!

Thanks!

 

 

 

 

Accepted Solution (1)

drakedev
Shopify Partner
696 150 237

This is an accepted solution.

Hi, that's normal, your a looping through all elements in the array and printing them.

Try to change it like this

{% for attribute in attributes %}
 {% assign key = attribute | first %}
 {% if key == 'your-key-name' %}
 *{{ attribute | first }} {{ attribute | last }}<br>
 {% endif %}
{% endfor %}
If my answer was helpful click Like to say thanks
If the problem is solved remember to click Accept Solution
Shopify/Shopify Plus custom development: You can hire me for simple and/or complex tasks.

View solution in original post

Replies 7 (7)

drakedev
Shopify Partner
696 150 237

This is an accepted solution.

Hi, that's normal, your a looping through all elements in the array and printing them.

Try to change it like this

{% for attribute in attributes %}
 {% assign key = attribute | first %}
 {% if key == 'your-key-name' %}
 *{{ attribute | first }} {{ attribute | last }}<br>
 {% endif %}
{% endfor %}
If my answer was helpful click Like to say thanks
If the problem is solved remember to click Accept Solution
Shopify/Shopify Plus custom development: You can hire me for simple and/or complex tasks.
John_jmk
Excursionist
22 0 5

Thank you so much @drakedev 

It worked brilliantly!

Sorry to ask another dumb question...Is there any way to assign multiple keys so that I can put multiple conditions in the {% if....%}?

E.g. {% assign key1 = xxxx %} , {% assign key2 = yyy %}

Thank you for your help!

drakedev
Shopify Partner
696 150 237

It is possible to add multiple conditions to an if, use if/elesif/else or use case/when to control the flow

If you explain the logic you want to implement I can give you some code examples

If my answer was helpful click Like to say thanks
If the problem is solved remember to click Accept Solution
Shopify/Shopify Plus custom development: You can hire me for simple and/or complex tasks.
Brendan-Zuza
Shopify Partner
10 0 3

Hi @drakedev

 

I have followed the above however it doesn't seem to work. Do you know if this still works currently?

 

Thanks, let me know

Brendan

Brendan
onlinegrowthgroup.com.au
PabloRam
Shopify Partner
2 0 0

Hi! 

i have an additional cart attribute in my cart template: 

 

<input
          required
          class="required"
          type="checkbox"
          name="attributes[Envoltura gratis]"
          value="Si"
          {% if cart.attributes['Envoltura gratis'] == 'Si' %}
            checked
          {% endif %}
>

how can i get this attribute in my packing slip template? i followed the solution above but it doesn't work for me 

 

I will appreciate your help

Thanks! 

Haider512
Shopify Partner
10 0 0

Same problem I am facing with attribute did you get any solution of this how to add attribute in packing slip?

Saboreandocr
Tourist
9 0 2

I have the same problem trying to add the order attributes to the print packaging form template but I can't get it to appear.

{% for attribute in attributes %}
{% assign key = attribute | first %}
{% if key == 'your-key-name' %}
*{{ attribute | first }} {{ attribute | last }}<br>
{% endif %}
{% endfor %}