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.
Starting a B2B store is a big undertaking that requires careful planning and execution. W...
By JasonH Sep 23, 2024By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024