App reviews, troubleshooting, and recommendations
How do i add empty cart feature in my marketplace
Hi @rajivmadan7, you can use this simple liquid snippet to clear the cart:
From your Shopify admin panel, go to Online Store > Themes > Edit Code.
In the sidebar, click the "Add a new snippet" button.
Name the snippet "clear-cart-button" and click the "Create snippet" button.
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>
Save the changes.
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.
June brought summer energy to our community. Members jumped in with solutions, clicked ...
By JasonH Jun 5, 2025Learn how to build powerful custom workflows in Shopify Flow with expert guidance from ...
By Jacqui May 7, 2025Did You Know? May is named after Maia, the Roman goddess of growth and flourishing! ...
By JasonH May 2, 2025