All things Shopify and commerce
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
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!
Solved! Go to the solution
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 %}
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 %}
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!
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
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
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!
Same problem I am facing with attribute did you get any solution of this how to add attribute in packing slip?
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 %}
Thanks to everyone who participated in our AMA with 2H Media: Marketing Your Shopify St...
By Jacqui Sep 6, 2024The Hydrogen Visual Editor is now available to merchants in Shopify Editions | Summer '...
By JasonH Sep 2, 2024Note: Customizing your CSS requires some familiarity with CSS and HTML. Before you cust...
By JasonH Aug 12, 2024