Managing Saved Carts with Liquid Forms
Three Liquid forms manage a customer's carts: cart_clear, cart_unset, and cart_delete. They look similar but keep different things, so choose based on what you want to preserve.
The three forms
cart_clear
Empties the current cart (removes all order lines)
The cart itself, including its promocode and selected address. The cart stays assigned to the session and remains in user.carts.
cart_unset
Removes the current cart from the session
Everything. The cart and its order lines are not deleted and remain accessible under user.carts.
cart_delete
Permanently destroys a cart
Nothing. The cart and its order lines are removed.
How to use each form
Empty a cart but keep it (cart_clear)
Use when the customer wants to start over but stay in the same cart, keeping any applied promocode and address.
{% form 'cart_clear' %}
<button type="submit">Empty cart</button>
{% endform %}Set the current cart aside (cart_unset)
Use to detach the current cart from the session without losing it. The customer can pick it up again later from their saved carts.
{% form 'cart_unset' %}
<button type="submit">Save for later</button>
{% endform %}Delete a cart (cart_delete)
With no parameter, cart_delete deletes the current session cart. To delete a specific saved cart instead, pass it with the cart: parameter.
How it works
cart_deleteis asynchronous. After a successful delete, the cart can take a moment to disappear fromuser.carts, and the page does not redirect on its own. If you are building a saved-carts page, refresh or update the list after the delete completes so the removed cart stops showing.cart_clearleaves an empty cart in place, so the customer stays in the same cart with their promocode and address intact.cart_unsetis the only non-destructive option: nothing is deleted, the cart is just removed from the active session.
Related
Liquid Forms (parent article)
Address_create Form Options
Last updated