WooCommerce

Cart Page

Use {{ cart }} on the cart page when you want to design the cart layout while WooCommerce still owns cart contents, totals, coupons, updates, and removals.

Create a normal page template for the WooCommerce cart page, then place cart tags inside it.

Smallest Cart Page#

phpresources/views/page-cart.php
<main class="cart-page">  {{ notices }}  {{ cart }}    {{ cart:items }}      <article class="cart-line">        <a href="{{ url }}">{{ title }}</a>        <span>{{ quantity }}</span>        <span>{{ line_total }}</span>      </article>    {{ else }}      <p>Your cart is empty.</p>    {{ /cart:items }}    <p>Total: {{ total }}</p>    <a href="{{ checkout_url }}">Checkout</a>  {{ /cart }}</main>

Read it like this:

  • {{ cart }} starts a cart context.
  • {{ cart:items }} loops over WooCommerce cart lines.
  • {{ else }} handles an empty cart.
  • {{ total }} and {{ checkout_url }} are cart values.
  • {{ title }}, {{ quantity }}, and {{ line_total }} are cart item values because they are inside {{ cart:items }}.

Cart Values#

Inside {{ cart }}, these value tags are available:

ValuePrints
count or item_countNumber of items in the cart.
cart_urlWooCommerce cart page URL.
checkout_urlWooCommerce checkout page URL.
subtotalWooCommerce formatted cart subtotal.
totalWooCommerce formatted cart total.

Example:

php
{{ cart }}  <p>Items: {{ count }}</p>  <p>Subtotal: {{ subtotal }}</p>  <p>Total: {{ total }}</p>  <a href="{{ checkout_url }}">Checkout</a>{{ /cart }}

Cart Item Values#

Inside {{ cart:items }}, these value tags are available:

ValuePrints
keyWooCommerce cart item key.
product_idProduct ID.
titleProduct name.
url or permalinkProduct URL. Variation cart items include variation_id and selected attribute_* query parameters.
quantityCart quantity.
priceFormatted unit price.
line_totalFormatted line total.
line_subtotalFormatted line subtotal.
product_image, featured_image, featured, or image_urlImage URL.
thumbnail_urlThumbnail URL.
thumbnail or imageWooCommerce image HTML.
remove_urlWooCommerce remove URL.

Example:

php
{{ cart:items }}  <article class="cart-line">    <img src="{{ thumbnail_url }}" alt="">    <a href="{{ url }}">{{ title }}</a>    <span>{{ price }}</span>    <span>{{ quantity }}</span>    <strong>{{ line_total }}</strong>  </article>{{ /cart:items }}

{{ subtotal }}, {{ total }}, {{ price }}, {{ line_total }}, {{ image }}, and {{ thumbnail }} can contain WooCommerce HTML. TemplateX renders those as safe WordPress HTML.

Update Quantities#

Use {{ cart:update }} inside {{ cart:items }}:

php
{{ cart }}  {{ cart:items }}    <article>      <a href="{{ url }}">{{ title }}</a>      {{ cart:update class="cart-quantity" }}        <input name="quantity" type="number" min="0" value="{{ quantity }}">        <button type="submit">Update</button>      {{ /cart:update }}      <strong>{{ line_total }}</strong>    </article>  {{ /cart:items }}{{ /cart }}

Setting quantity to 0 removes the line through WooCommerce's normal cart logic.

{{ cart:update }} renders a form. Do not put it inside another form.

Remove Items#

Use {{ cart:remove }} inside {{ cart:items }}:

php
{{ cart }}  {{ cart:items }}    <article>      <a href="{{ url }}">{{ title }}</a>      {{ cart:remove class="cart-remove" }}        <button type="submit" aria-label="Remove {{ title }}">Remove</button>      {{ /cart:remove }}    </article>  {{ /cart:items }}{{ /cart }}

{{ cart:remove }} renders a form with the current cart item key.

Coupons#

Use {{ coupon }} wherever a coupon form belongs:

php
{{ coupon class="coupon-form" }}  <label>    Coupon code    <input name="coupon_code" autocomplete="off">  </label>  <button type="submit">Apply</button>{{ /coupon }}

{{ coupon }} renders a form. Do not place it inside another form or inside {{ checkout:form }}.

Runtime Behavior#

With JavaScript enabled, cart update, remove, and coupon forms refresh cart count, cart item content, and cart values in place. They also dispatch a bubbling cart:updated event.

Without JavaScript, update, remove, and coupon forms post normally and WooCommerce updates the cart on the next page load.

For header drawers and overlays, see Mini-Cart.