Shopping cart

11 0 0

How do i add empty cart feature in my marketplace

Reply 1 (1)
Shopify Partner
46 12 15

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!');
    .catch((error) => {
      console.error('Error clearing cart:', error);
  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.

Helping merchants build super unique, high-performance storefronts using Weaverse + Hydrogen.
Looking for Development & Agency partners.
If you find the answer helpful, give it a thumbs up!
Our App: Weaverse Hydrogen Theme Customizer