<p>This method <a href="https://docs.craftcms.com/commerce/api/v5/craft-commerce-services-carts.html#method-forgetcart" rel="nofollow noreferrer">still exists</a>, so I'm not sure what would be causing problems after the migration.</p>
<p>In general, I wouldn't recommend removing the cart cookie on every request, as it will effectively make the cart unusable. Is it possible that the site was previously working <em>in spite of</em> this being in your template?</p>
<p>You can always manually clear a cart for testing with <a href="https://craftcms.com/docs/commerce/5.x/development/cart.html#forgetting-a-cart" rel="nofollow noreferrer">a form like this</a>!</p>

CC BY-SA 4.0
2024-11-06T15:27:13.283Z
I am aware of the fact that is empties the cart but this was a deliberate need as we don't want users to have the option to buy more than one product at a time. I know we can empty the cart with a form but I wanted it to happen automatically without an action from a user...
LessMore Creative Studio
CC BY-SA 4.0
2024-11-05T20:51:25.563Z
2024-11-05T20:51:25.563Z
August Miller
<p>I upgraded to commerce 5 from commerce 4 and a simple line of code got broken...</p>
<pre><code>{{ craft.commerce.carts.forgetCart() }}
</code></pre>
<p>I used it in the top of my template to make sure the cart is empty when I load the page. I couldn't find the syntax change in the docs...
Any help would be appreciated!!</p>

<templating><plugin-craftcommerce>
Emptying Cart Commerce 5
# Emptying Cart Commerce 5

(Asked by: username_0 on 2024-11-05)

I upgraded to commerce 5 from commerce 4 and a simple line of code got broken...
{{ craft.commerce.carts.forgetCart() }}

I used it in the top of my template to make sure the cart is empty when I load the page. I couldn't find the syntax change in the docs...
Any help would be appreciated!!

**Tags:** templating, plugin-craftcommerce

---

## 1 answers

### Answer by username_1 on 2024-11-05. Score: 0

This method [still exists](https://docs.craftcms.com/commerce/api/v5/craft-commerce-services-carts.html#method-forgetcart), so I'm not sure what would be causing problems after the migration.

In general, I wouldn't recommend removing the cart cookie on every request, as it will effectively make the cart unusable. Is it possible that the site was previously working *in spite of* this being in your template?

You can always manually clear a cart for testing with [a form like this](https://craftcms.com/docs/commerce/5.x/development/cart.html#forgetting-a-cart)!

> **Comments:**
> **username_0**: I am aware of the fact that is empties the cart but this was a deliberate need as we don't want users to have the option to buy more than one product at a time. I know we can empty the cart with a form but I wanted it to happen automatically without an action from a user...  

---

