Liquid Template Variables - cart
From Spiffy Stores Knowledge Base
The Liquid template variable cart has the following attributes:
Contents
cart.item_count
Returns the number of items currently in the shopping cart.
For example:
{% if cart.item_count == 0 %} Your shopping cart is empty! {% else %} You have <a href="/cart">{{ cart.item_count }} {{ cart.item_count | pluralize: 'item', 'items' }}</a> in your cart {% endif %}
cart.items
Returns all the items in the shopping cart. Each item is a line item.
For example:
<ul> {% for item in cart.items %} <li>{{ item.title }}</li> {% endfor %} </ul>
cart.total_price
Returns the total price of all items in the shopping cart.
For example:
The total of your cart is: {{ cart.total_price | money }}
cart.total_weight
Returns the total weight of all items in the shopping cart.
Weight is always returned as grams. Use weight or weight_with_unit filter to display the actual weight in your preferred unit system.
The total of your cart is: {{ cart.total_weight | weight_with_unit }}
cart.cart_discount
Returns the total shopping cart discount that has been applied to the current items in the shopping cart.
This value can be used in cart.liquid to display a message to the customer informing them of how much they are saving.
{% if cart.cart_discount > 0 %} Your discount today is {{ cart.cart_discount | money }} {% endif %}
cart.discounts
Returns an array of shopping cart discount descriptions that are currently available for the cart.
This a list of all possible shopping cart discounts that could be applied to the cart, but it does not necessarily mean that items in the cart are eligible for the discount.
{% if cart.discounts contains 'Bonus Gift' %} We currently have a special Bonus Gift promotion running. {% endif %}
cart.eligible_discounts
Returns an array of shopping cart discount descriptions that are currently eligible for the cart.
Some discounts are always eligible and active at the same time. For example, if you need to spend $100 to get a 10% discount, then once you've spent $100 you're eligible for the discount which can be applied immediately.
Other discounts may offer you a discount on other items when you add them to the cart. For example, if you spend $100 you may be able to add additional items from a specific collection with a 50% discount. Once you've spent $100 you're eligible for the discount, but the discount itself is not active because you haven't added the items to the cart that can be discounted. Once the items have been added, then the discount is active.
This value can be used in cart.liquid to display a message to the customer informing them of special offers or letting them know how much they need to add to the cart to take advantage of a special offer.
{% if cart.eligible_discounts contains 'Bonus Gift' %} Good news! You can now add an item from the bonus gift collection for free! {% endif %}
cart.active_discounts
Returns an array of shopping cart discount descriptions that are currently active for the cart.
This value can be used in cart.liquid to display a message to the customer informing them of special offers or letting them know how much they need to add to the cart to take advantage of a special offer.
{% if cart.active_discounts contains 'Bonus Gift' %} Good news! Your bonus gift is in your shopping cart. {% endif %} {% unless cart.active_discounts contains 'Free Shipping' %} You only need to spend {{ 100 | minus: cart.total_price | money }} to receive free shipping. {% endunless %}
cart.unused_discounts
Returns an array of shopping cart discount descriptions that are currently unused for the cart.
A discount is unused if it is eligible for the current contents of the cart, but has not yet been applied to the cart.
This value can be used in cart.liquid to display a message to the customer informing them of special offers or letting them know how much they need to add to the cart to take advantage of a special offer.
{% if cart.unused_discounts contains 'Bonus Gift' %} You don't yet have a bonus gift is in your shopping cart. {% endif %}
cart.note
You have the option of adding a note field to your checkout template. This may be used to collect information from the customer on any special requests they have for the order.
This is used by defining an input field named “note” in the form that submits to ”/cart” in cart.liquid.
For example:
<p> <label for="notes">Extra notes or special instructions</label> <input type="text" id="notes" name="note" size="60" value="{{ cart.note }}" /> </p>
Please note that you can also activate an "Additional Checkout Comments" field during checkout to collect similar information. This option can be enabled through the "Preferences" -> "Checkout & Payment" options. This option may be simpler to implement as it does not require any theme template customization to enable.
More detailed examples are available at Asking your customer for additional information.
cart.attributes
The attributes property is similar to the note property above in that it is an optional field that you can add to your store’s checkout form. Simply define an input field named "attributes[]" and it will be captured automatically and displayed on the order detail page in your Toolbox.
For example, if you want to capture the type of gift wrapping the customer wants, then you can add this to your cart.liquid template.
<p> <label for="wrapping">Gift Wrapping:<label> <select name="attributes[gift_wrapping]" id="wrapping"> <option value="none"{% if cart.attributes.gift_wrapping == "none" %} selected{% endif %}> None needed...</option> <option value="wrapping"{% if cart.attributes.gift_wrapping == "wrapping" %} selected{% endif %}> Gift Wrapping</option> <option value="box"{% if cart.attributes.gift_wrapping == "box" %} selected{% endif %}> Gift Box</option> </select> </p>
More detailed examples are available at Asking your customer for additional information.