How can I introduce an empty cart feature in my marketplace?

Topic summary

A user seeks to add an empty cart feature to their Shopify marketplace. Two solutions are provided:

Custom Code Approach:

  • Create a new snippet called “clear-cart-button” in the theme editor
  • Add provided JavaScript code that uses Shopify’s /cart/clear.js endpoint
  • Insert the snippet using {% render 'clear-cart-button' %} wherever the button should appear
  • The button triggers a fetch request to clear the cart and refreshes the page

App-Based Solution:

  • Install the “Shopify Clear Cart” app by Addify from the Shopify App Store
  • Offers one-click cart clearing functionality
  • Includes customization options for button text, styling, and placement
  • Provides optional confirmation pop-ups and post-clear redirect settings

Both methods allow customers to empty their entire cart at once rather than removing items individually. The discussion remains open with no indication of which solution the original poster chose.

Summarized with AI on October 23. AI used: claude-sonnet-4-5-20250929.

How do i add empty cart feature in my marketplace

Hi @rajivmadan7 , you can use this simple liquid snippet to clear the cart:

  1. From your Shopify admin panel, go to Online Store > Themes > Edit Code.

  2. In the sidebar, click the “Add a new snippet” button.

  3. Name the snippet “clear-cart-button” and click the “Create snippet” button.

  4. In the newly created file, paste the following code:

<button id="clear-cart-btn" onclick="clearCart()">Clear Cart</button>

<script>function clearCart() {
  fetch('/cart/clear.js', { method: 'POST' })
    .then(() => {
      console.log('Your cart has been cleared!');
      location.reload();
    })
    .catch((error) => {
      console.error('Error clearing cart:', error);
    });
}</script>
  1. Save the changes.

  2. To add the “Clear Cart” button to a page, include/render the following liquid code snippet wherever you want the button to appear:

{% render 'clear-cart-button' %}

That’s it! When a customer clicks on the “Clear Cart” button, it will trigger a fetch request to clear the cart, log a message, and refresh the page.

2 Likes

You can easily add an “Empty Cart” or “Clear Cart” feature to your marketplace using the Shopify clear cart app by Addify.

It lets customers empty their entire cart with a single click, instead of removing items one by one. You can fully customize the button text, style, and placement to match your theme. You can also choose whether to show a confirmation pop-up or automatically redirect shoppers after clearing their cart.