Cart - Use cart attributes to collect more information

Highlighted
Community Manager
Community Manager
487 28 697

Cart attributes are custom form fields that let you collect additional information from your customers on the cart page. The information that you collect will display in a note on the customer's order in the admin. For example, if you want to ask customers how they heard about your store, then you can add an How did you hear about us? drop-down selection question to the cart.

 

Tip: Cart attributes are different from order notes and line item properties. Order notes, which are available in every free Shopify theme, let you capture special instructions on how to prepare and deliver an order. Line item properties are used to record customization information about specific products in an order. Line item properties are specified directly on the product page.

Sectioned themes and non-sectioned themes

 

The steps for this tutorial differ depending on whether you are using a sectioned or a non-sectioned theme. A sectioned theme is a newer theme that lets you drag and drop to arrange the layout of your store's pages.

 

To figure out whether your theme supports sections, go to the theme's Edit code page. If there are files in the Sections directory, you are using a sectioned theme. Non-sectioned themes were released before October 2016, and do not have files in the Sections directory.

 

If you are using a sectioned theme, then click the Sectioned themes button and follow the instructions. If you are using an older, non-sectioned theme, then click the Non-sectioned themes button and follow the instructions.

 

 

TyW | Online Community Manager @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

2 Likes
Highlighted
Community Manager
Community Manager
487 28 697

Sectioned Themes

 

 

Create a cart attribute field

 

 

You can add as many custom form fields to your cart form as you need. You can use the Shopify UI Elements Generator tool to easily generate the HTML and Liquid code for each form field that you want to add to your cart page. This tool was created by Shopify to help simplify the process of adding custom user interface elements, such as form fields and icons, to Shopify themes.

 

  1. Go to the Shopify UI Elements Generator.
  2. In the Set your form field section, select the type of form element that you want to use from the Type of form field drop-down menu:

    cart-att-01.jpg

  3. Enter a label for Your form field label.
  4. If you want your theme to prevent customers from reaching the checkout before they have filled in your form field, check Required.
  5. You can see a preview of your form field in the Preview section.
  6. Copy the generated code from the box in the Grab your code section.

 

 

Add a form field to your theme code

 

 

To add a custom form field:

 

  1. From your Shopify admin, go to Online Store > Themes.
  2. Find the theme you want to edit, and then click Actions > Edit code.
  3. In the Sections directory, clickcart-template.liquid. If your theme doesn't have acart-template.liquid, then, in the Templates directory, click cart.liquid.
  4. Find the closing </form> tag in the code.
  5. On a new line right above the closing </form> tag, paste the code that you copied from the Shopify UI Elements Generator. You can experiment with putting the code in different places to see where the form field appears on your cart page.
  6. If you set your form field to be required, then you will need to remove the novalidate attribute from the checkout form. Find novalidate, which is inside the opening <form> tag. The code might look something like this:

    <form action="/cart" method="post" novalidate class="cart">

     

    Delete novalidate:

    <form action="/cart" method="post" class="cart">

     

  7. Click Save.

The new field is shown on the order page of your admin in the Additional Details section.

Note: Cart attributes can be added only to a cart page, and are not compatible with cart drawers, or cart popups. To change your cart style, go to the theme editor.

 

 

Show cart attributes in email templates

 

 

You can show cart attribute information for orders in your email notification templates. To add cart attributes to an email template, add the following code to the template in the place that you would like the cart attributes to be shown:

 

 

<h4>Additional details</h4>
<p>
{% for attribute in attributes %}
{{ attribute | first }}: {{ attribute | last }}<br>
{% endfor %}
</p>

 


Show cart attributes in Order Printer templates

 

 

If you use the Order Printer app to print your orders, you can add some code to your templates to show cart attributes on your printouts. To add cart attributes to an Order Printer template, add the following code to the very bottom of the template:

 

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

 

TyW | Online Community Manager @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

5 Likes
Highlighted
Community Manager
Community Manager
487 28 697

Non-sectioned Themes

 

 

Create a cart attribute field

 

 

You can add as many custom form fields to your cart form as you need. You can use the Shopify UI Elements Generator tool to easily generate the HTML and Liquid code for each form field that you want to add to your cart page. This tool was created by Shopify to help simplify the process of adding custom user interface elements, such as form fields and icons, to Shopify themes.

 

  1. Go to the Shopify UI Elements Generator.
  2. In the Set your form field section, select the type of form element that you want to use from the Type of form field drop-down menu:

    cart-att-01.jpg

  3. Enter a label for Your form field label.
  4. You can see a preview of your form field in the Preview section.
  5. Copy the generated code from the box in the Grab your code section.

 

 

Add a form field to your theme code

 

 

To add a custom form field:

 

  1. From your Shopify admin, go to Online Store > Themes.
  2. Find the theme you want to edit, and then click Actions > Edit code.
  3. In the Sections directory, click cart-template.liquid. If your theme doesn't have acart-template.liquid, then, in the Templates directory, click cart.liquid.
  4. Find the closing </form> tag in the code.
  5. On a new line right above the closing </form> tag, paste the code that you copied from the Shopify UI Elements Generator. You can experiment with putting the code in different places to see where the form field appears on your cart page.
  6. If you set your form field to be required, then you will need to remove the novalidate attribute from the checkout form. Find novalidate, which is inside the opening <form> tag. The code might look something like this:

    <form action="/cart" method="post" novalidate class="cart">

     

    Delete novalidate:

    <form action="/cart" method="post" class="cart">

     

  7. Click Save.

The form field is shown on the order page of your admin in the Additional Details section.

Note: Cart attributes can be added only to a cart page, and are not compatible with cart drawers, or cart popups. To change your cart style, go to the theme editor.

 

 

Show cart attributes in email templates

 

 

You can show cart attribute information for orders in your email notification templates. To add cart attributes to an email template, add the following code to the template in the place that you would like the cart attributes to be shown:

 

<h4>Additional details</h4>
<p>
{% for attribute in attributes %}
{{ attribute | first }}: {{ attribute | last }}<br>
{% endfor %}
</p>

 


Show cart attributes in Order Printer templates

 

 

If you use the Order Printer app to print your orders, you can add some code to your templates to show cart attributes on your printouts. To add cart attributes to an Order Printer template, add the following code at the very bottom of the template:

 

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

 

TyW | Online Community Manager @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

1 Like
Highlighted
Shopify Partner
16 0 4

Where do I find the "Order Printer" template that you mention in your post? 

(I'm running Supply, and not finding it.) 

THX

Custom sites and stores by Squareflair.com
0 Likes
Highlighted
New Member
7 0 0

Hi TyW

I have followed your instructions and pasted the code that was generated by the Shopify UI Elements Generator. The preview showed me exactly how I wanted this form field to look.   I wanted to create a form field with a drop down list for the customer to select their preferred charity.   
When I tested it and viewed how the Cart page looked, I found that ONLY the Label name came up and the drop down field was not visible.  

Any clues as to what I might have done wrong here?  
I have attached the screenshot of my cart-template.liquid within my theme showing you where I embedded the code the the UI Elements generator created. 

I have also attached the screenshot of what my shopping cart looks like after I embedded the code. 
For your reference, the theme I'm using is Envy by Wetheme.  

Any help would be very much appreciated.  

 

thanks

Mich

 Screenshot - cart template liquid .pngScreenshot Shopping Cart page .png


0 Likes
Highlighted
Excursionist
33 0 3

this worked perfectly

0 Likes
Highlighted
Tourist
4 0 3

Hello, this tutorial is really helpful and I manage to add a required checkbox on my cart page.

However, the "required" field in combination with the removal of "novalidate" attribute in the form doesn't prevent the customer to proceed with checkout through the additional checkout buttons (Google Pay, Apple Pay etc). Is there any way to block the user to compile required fields before heading to the quick checkout experience?

 

Thanks in advance

0 Likes
Highlighted
Excursionist
33 0 3

Strange, worked well for me. I removed 'novalidate' in the <form action...

and then used this code for my usecase:

 

Hello - Here's what I did to ensure that customers complete the newly added fields before being allowed to go to checkout

 

     <p class="cart-attribute__field">
        <label for="customer-name"><font color="BLACK"><strong>కస్టమర్ పేరు</strong></label></font></label> 
  <input required class="required" id="customer-name" type="text" name="attributes[Customer Name: ]" value="{{ cart.attributes["Customer Name"] }}">
</p> 

 

0 Likes
Highlighted
New Member
2 0 0

Hi, thanks for the tutorial but it doesnt work in my website, I put the code below <form> tag.

Thanks!

 

Sin título.png

0 Likes
Highlighted
New Member
1 0 0

@gab33 I have the same problem. Did you find a solution, please?

0 Likes