Clear cart

Remove all items from a customer's cart.

Use the clear_cart form tag to remove all items from a customer's cart.

Basic usage

{% form "clear_cart" %}
  <input type="submit" value="Clear cart" />
{% endform %}

Submitting the form removes every line item from the customer's cart.

Redirect after clearing the cart

By default, the customer is returned to the current page after the cart has been cleared.

To redirect the customer elsewhere, use the return_to parameter.

{% form "clear_cart", return_to: "/cart" %}
  <input type="submit" value="Clear cart" />
{% endform %}

Developer considerations

When implementing a clear cart action:

  • Make it clear that all items will be removed from the cart.
  • Consider asking for confirmation before clearing the cart if the action is easily triggered.
  • Use the return_to parameter to control where customers are redirected after the cart is cleared.

On this page