Have your say in Community Polls: What was/is your greatest motivation to start your own business?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Error Message on Cart Screen, Functions Just Fine (custom attribute in main-cart-items.liquid)

Error Message on Cart Screen, Functions Just Fine (custom attribute in main-cart-items.liquid)

Dojindo
Tourist
5 0 5

Hello!

 

My store's current URL is https://nagata-4528.myshopify.com/

 

Inspired by this (likely outdated) guide: https://community.shopify.com/c/shopify-design/cart-use-cart-attributes-to-collect-more-information/...

 

We added a line to our theme's code (generated by the Shopify UI Elements Generator) into the "main-cart-items.liquid" file of our theme in order for our customers to attach a purchase order # to their orders. 

 

The line we added was placed just before the </form> as suggested in the guide above. The line is as follows below:

 

<p class="cart-attribute__field"><label for="purchase-order">Purchase Order #</label><input form="cart" id="purchase-order" type="text" name="attributes[Purchase Order #]" value="{{ cart.attributes["Purchase Order #"] }}"></p>

 

It actually works perfectly fine, except when a customer inputs a string into the field, the cart screen generates a message of "There was an error while updating your cart. Please try again." underneath the "Check out" button.

 

Despite this message, the order processes normally, and the value entered by the customer appears under "additional information" from the admin side.

 

How can we avoid this error? 

 

Also, if possible, can this PO# be referenced in the subject or body of the order confirmation email sent to customers? I was able to reference other fields in the email, but I am not as familiar with Liquid.

 

Thank you!

Reply 1 (1)

Crimson_Shot
Excursionist
12 1 1

Just move the line you added (the code snippet) and place it right after the </form> tag and that should fix your issue. Make sure that your code is before the </cart-items> tag just like the screenshot below.

 

I attached the same file you uploaded after editing it.