App reviews, troubleshooting, and recommendations
Hi,
I have customer input fields on my cart and this provides me with several fields of answers when a customer orders.
This works well and comes through to my admin order email and printer pro. However, I would like to shows the fields separately in the order printer pro template.
Currently, I have:
{% for attribute in attributes %} <strong>{{ attribute | first }}:</strong> {{ attribute | last }}<br /> {% endfor %}
The above shows:
First Name: Person
Last Name: Person Last name
Date of Birth: 24/09/45
Gender: Female
Results: Yes I would Like Reported Results
The above works but brings over all the fields, 5 rows in total. I would like to show only 4 of those fields as below.
First Name: Person
Last Name: Person Last name
Date of Birth: 24/09/45
Gender: Female
I have tried this:
{% assign SETTING_show_cart_attributes = true %}
SURNAME:{{ attributes.last-name }}
SURNAME:{{ cart.attributes.last-name }}
SURNAME:{{ last-name }}
Any help would be much appreciated.
Keith
Hi @ukbh:
You can try this:
{% for attribute in attributes %} {% assign attr_name = attribute | first %} {% assign attr_value = attribute | last %} {% unless attr_name == 'Result' %} <strong>{{ attr_name}}:</strong> {{ attr_value }}<br /> {% endunless %} {% endfor %}
Apologies for the delay, only just got back into work!
Many thanks for your reply on this, I added this in and this brings back all custom attributes from the cart:
Patient First name: yjhryjh
Patient Last Name: drtjdrtj
Patient Date of Birth: 12/12/1987
Patient Gender: Female
Reported Results: Yes I would Like Reported Results
I am hoping to split them up, so I only show the below in summary:
Patient First name: yjhryjh
Patient Last Name: drtjdrtj
Patient Date of Birth: 12/12/1987
Patient Gender: Female
And these by themselves in different parts of the order PDF:
yjhryjh will be attending, and their last name is drtjdrtj and their DOB is 12/12/1987
many thanks for your help.
Keith
Hi, @ukbh:
So the code needs a little adjust:
{% for attribute in attributes %} {% assign attr_name = attribute | first %} {% assign attr_value = attribute | last %} {% unless attr_name == 'Reported Results' %} <strong>{{ attr_name}}:</strong> {{ attr_value }}<br /> {% endunless %} {% endfor %}
About the PDF, it's not possible to edit that report without using an App.
Hi @ukbh:
We are glad to know that, please give us a like and mark the solution to help other people to find it. Thank you.
Hi @PremierStores , thanks for sharing this it worked well for my application.
What would the code be if I wanted to ignore 2 of the attribute lines?
Hi @ukbh
I know its an old question, but I recently had the same problem: Wanting to access a specific cart attribute on an order printer template. (And not wanting a for loop with an if statement, just to access this single attribute.) In my case the attribute is called pet-name.
I also tried many combinations of attributes.pet-name .
when I just tried
{{ attributes }}
I got this output:
{"pet-name"=>"Fido ", "backside-text"=>"Call 123 456 789 if found.", "delivery-date"=>"06-29-2022"}
What ended up working for me was pretending that attributes was an array, and using [ ] to access the desired item.
But instead of using a number to index the array (e.g. {{ my_array[0] }} ), I used a string:
{{ attributes["pet-name"] }}
This gave me the output I wanted:
Fido
I don't know why this works, or why {{ attributes.pet-name }} as per the documentation doesn't work. I just got inspired to try [ ] with a string, when I got the output from attributes witch kinda looked like an array of strings. (I have very limited web programming experience so I may use the terminology completely wrong, I'm sorry)
Best regards
krrr
Thanks KRR, I'll try this tomorrow as I went ahead and kept all of them in.
Cheers
Keith
We're excited to announce improvements to the threaded messaging experience in our communi...
By TyW May 31, 2023Thank you to everyone who participated in our AMA with Klaviyo. It was great to see so man...
By Jacqui May 30, 2023Photo by Marco Verch Sales channels on Shopify are various platforms where you can sell...
By Ollie May 25, 2023