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.
Make the shift from discounts to donations, and witness your business not only thrive fina...
By Holly Dec 4, 2023On our Shopify Expert Marketplace, you can find many trusted third party developers and fr...
By Arno Nov 27, 2023You've downloaded the Search & Discovery app from the Shopify App store, and as you're ...
By Skye Nov 8, 2023