Is there a way to automatically add default cart attributes to every order?

mahfood
Tourist
7 0 3

I was trying to find a way to add information to an order from the admin page that can then be printed in an invoice copy with said information. I cannot use the "Order Notes" as customers may need this to make certain requests and will use this section, and I presume if edited they will be able to see it in their accounts?

I need it for something internal in my company that should not be visible to customers.

I have found about Cart Attributes which can be recalled in an invoice template and are perfect for my application, however I am not sure how to add them to the cart.liquid without there being an input required by the customer. I basically want the following cart attributes to be added automatically to every order:

 

"Weight"

"Waste"

Both attributes to have a default value of 0 (or blank if possible)

 

Then I can edit their values in the order admin page (as I can with customer-input attributes) to then add the appropriate values which can then be printed with the internal copy of the invoice. I have already set up 2 templates in the order printer one for the customer copy and another for the internal copy which include the attributes and have verified it will work for my needs. I just need a way to add the attributes by default to every order without it being visible to customers in the cart page.

 

Thanks in forward.

0 Likes
PaulNewton
Shopify Partner
2819 161 519

Use the following guide but set the type attribute to hidden

https://community.shopify.com/c/Shopify-Design/Cart-Use-cart-attributes-to-collect-more-information/...

 

Example

  <input id="weight" type="hidden" name="attributes[Weight]" value="{{ cart.attributes["Weight"] }}">

 Use double underscores to make attributes hidden https://shopify.dev/api/liquid/objects/cart#cart-attributes 

Problem Solved? ✔️Accept and ? Like the solution so you can help others.
Buy me a coffee ☕ paypal.me/paulnewton or donate to eff.org
Confused? Busy? Buy a custom solution paull.newton+shopifyforum@gmail.com
mahfood
Tourist
7 0 3

Thank you for your response

 

I tried adding it to the cart.liquid form as you suggested, however it doesn't show up  in the order page in the admin panel

This is my code

<p class="cart-attribute__field">
  <label for="weight"> </label>
  <input id="weight" type="hidden" name="attributes[Weight]" value="{{ cart.attributes["Weight"] }}">
</p>

 

I presume this is because a default value is not established and the attribute function doesn't accept blank values?

If so how can I make a default value of, say, "0" for the attribute?

Or is this something related to the double underscore? if so to which part am I supposed to add it?

0 Likes
mahfood
Tourist
7 0 3

I managed to get this working

 

Only added the following lines to the cart.liquid

<input type="hidden" name="attributes[Weight]" value="0">
<input type="hidden" name="attributes[Waste]" value="0">

 

I am still not clear what the double underscores do and hide the attributes from whom/what exactly, but the code above creates the 2 attributes with the value "0" which I can access via order page, but none are visible to the customer.

0 Likes