Answers.Body: <p>Depending on context, here's another handy way of clearing the cart for Commerce 2/3</p>
  
  <p>In a template, you can put:</p>
  
  <pre><code>{% do cart.setLineItems([]) %}
  {% do craft.app.elements.saveElement(cart) %}
  </code></pre>
  
  <p>You could e.g. just use a direct link to a template that does that, and in turn re-directs to wherever...if you don't want to muck around with a form.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-05-10T05:43:48.103Z
Answers.LastActivityDate: 2020-05-10T05:43:48.103Z
Answers.UserDisplayName: Jeremy Daalder
Answers.Body: <p>The <code>commerce/cart/remove-all-line-items</code> action (or in Craft 2 terms, <code>commerce/cart/removeAllLineItems</code>) was deprecated (<a href="https://github.com/craftcms/commerce/blob/develop/CHANGELOG.md#300---2020-01-28" rel="nofollow noreferrer">and subsequently removed</a> in Commerce 3), so it's up to you to build a form to explicitly delete all line items:</p>
  <pre class="lang-php prettyprint-override"><code>&lt;form method=&quot;post&quot;&gt;
      {{ csrfInput() }}
      {{ actionInput('commerce/cart/update-cart') }}
  
      {% for lineItem in craft.commerce.carts.cart.lineItems %}
          &lt;input type=&quot;hidden&quot; name=&quot;lineItems[{{ lineItem.id }}][remove]&quot; value=&quot;✓&quot;&gt;
      {% endfor %}
  
      &lt;button type=&quot;submit&quot;&gt;Empty Cart&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  <p>This snippet just loops over the current line items, and outputs a hidden <code>input</code> element, which sends the proper <code>POST</code> value to the <code>update-cart</code> action.</p>
  <p>It's also possible to give your customer control over which line items are to be removed by changing the <code>input</code> to a check-box (and providing adequate labeling).</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-05-08T17:53:59.960Z
Answers.Text: Has `The commerce/cart/remove-all-line-items` changed? I get this "**Unable to resolve the request: commerce/cart/remove-all-line-items**" when I try to empty my cart. This worked previously for me, but not anymore.
Answers.UserDisplayName: Darryl Hardin
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-05-09T02:15:56.953Z
Answers.Text: I think your answer at the beginning of the reply! This action was deprecated, and appears to have been completely removed in Commerce 3. You should be able to use the provided snippet with the consolidated `update-card` action.
Answers.UserDisplayName: August Miller
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-05-12T14:36:15.050Z
Answers.Text: Awe, I read that as the craft2 was deprecated, which I was aware of, didn't realize the first was as well.
Answers.UserDisplayName: Darryl Hardin
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-16T05:28:06.377Z
Answers.LastActivityDate: 2021-03-10T19:33:59.620Z
Answers.LastEditDate: 2021-03-10T19:33:59.620Z
Answers.UserDisplayName: August Miller
Body: <p>How do you reset or empty the cart, in Commerce 2? There is no mention of this in the documentation.</p>
  
  <p>In Commerce 1, it was possible to issue a request to the <code>commerce/cart/removeAllLineItems</code> action to clear the cart, but this no longer works.</p>
  
Tags: <plugin-craftcommerce>
Title: How do you reset a cart under Craft Commerce 2?
ThreadText: # How do you reset a cart under Craft Commerce 2?
  
  (Asked by: username_0 on 2018-08-15)
  
  How do you reset or empty the cart, in Commerce 2? There is no mention of this in the documentation.
  
  In Commerce 1, it was possible to issue a request to the `commerce/cart/removeAllLineItems` action to clear the cart, but this no longer works.
  
  **Tags:** plugin-craftcommerce
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2018-08-16. Score: 5 | Accepted answer
  
  The `commerce/cart/remove-all-line-items` action (or in Craft 2 terms, `commerce/cart/removeAllLineItems`) was deprecated ([and subsequently removed](https://github.com/craftcms/commerce/blob/develop/CHANGELOG.md#300---2020-01-28) in Commerce 3), so it's up to you to build a form to explicitly delete all line items:
  
  ```php
  <form method="post">
      {{ csrfInput() }}
      {{ actionInput('commerce/cart/update-cart') }}
  
      {% for lineItem in craft.commerce.carts.cart.lineItems %}
          <input type="hidden" name="lineItems[{{ lineItem.id }}][remove]" value="✓">
      {% endfor %}
  
      <button type="submit">Empty Cart</button>
  </form>
  
  ```
  
  This snippet just loops over the current line items, and outputs a hidden `input` element, which sends the proper `POST` value to the `update-cart` action.
  
  It's also possible to give your customer control over which line items are to be removed by changing the `input` to a check-box (and providing adequate labeling).
  
  > **Comments:**
  > **username_3**: Has `The commerce/cart/remove-all-line-items` changed? I get this "**Unable to resolve the request: commerce/cart/remove-all-line-items**" when I try to empty my cart. This worked previously for me, but not anymore.  
  > **username_2**: I think your answer at the beginning of the reply! This action was deprecated, and appears to have been completely removed in Commerce 3. You should be able to use the provided snippet with the consolidated `update-card` action.  
  > **username_3**: Awe, I read that as the craft2 was deprecated, which I was aware of, didn't realize the first was as well.  
  
  ---
  
  ### Answer by username_1 on 2020-05-10. Score: 6
  
  Depending on context, here's another handy way of clearing the cart for Commerce 2/3
  
  In a template, you can put:
  
  ```
  {% do cart.setLineItems([]) %}
  {% do craft.app.elements.saveElement(cart) %}
  
  ```
  
  You could e.g. just use a direct link to a template that does that, and in turn re-directs to wherever...if you don't want to muck around with a form.
  
  
  ---
  
  