Answer the question
In order to leave comments, you need to log in
How to empty the shopping cart after ordering?
Good day, I'm almost done with the site and I'm stuck on the question of emptying the cart, I want to delete all the items that are in the cart when a person makes an order
I have a code to remove an item from the cart
//удаляем товар из корзины
function delGoods() {
let id = $(this).attr('data-id');
delete cart[id];
saveCart();
showCart();
}
function saveCart() {
//сохраняю корзину в localStorage
localStorage.setItem('cart', JSON.stringify(cart)); //корзину в строку
}
<div class="main-cart"></div>
Answer the question
In order to leave comments, you need to log in
Look at the showCart function. Under what conditions does it draw an empty cart, put this state in cart.
function delGoods()
{
cart = {}; // ... я поставил пустой объект, к примеру.
saveCart();
showCart();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question