FROM CACHE - en_header

Show separate custom cart attribute fields in order printer pro

ukbh
Shopify Partner
7 0 0

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

Replies 7 (7)
PremierStores
Shopify Partner
279 27 51

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 %}
Let's make the best store!
Contact us at: thepremierstores@gmail.com
ukbh
Shopify Partner
7 0 0

Hi @PremierStores 

 

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

PremierStores
Shopify Partner
279 27 51

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.

Let's make the best store!
Contact us at: thepremierstores@gmail.com
ukbh
Shopify Partner
7 0 0

@PremierStores  thankyou, that's great, gets rid of the 5th option 🙂

 

Many thanks

PremierStores
Shopify Partner
279 27 51

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.

Let's make the best store!
Contact us at: thepremierstores@gmail.com
krrr
New Member
1 0 1

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

ukbh
Shopify Partner
7 0 0

Thanks KRR, I'll try this tomorrow as I went ahead and kept all of them in.

 

Cheers

Keith