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 %}
Starting a B2B store is a big undertaking that requires careful planning and execution. W...
By JasonH Sep 23, 2024By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024