I’m coming close to finishing my task for my client, but I am currently having trouble with one of the tasks I need to complete. I was given a request to hide the Shopping Cart when it is empty and appear when it is full. I’m having trouble finding the api within Wix Stores or anything code related that ties into whenever the cart is empty or not. Is there any possibilities to get deep into this? Hope to hear from you guys and thank you for your time.
Since it’s now 2022, here’s a temporary solution via Velo | masterPage.js:
// masterPage.js
// The code in this file will load on every page of your site
$w.onReady(function () {
hideEmptyCart(/* The Wix ID */ 'cartIcon');
});
import { cart } from 'wix-stores';
function hideEmptyCart(id) {
cart.getCurrentCart().then(initialCart => switchIcon(initialCart));
cart.onChange(changedCart => switchIcon(changedCart));
function switchIcon(aCart) {
let count = aCart.lineItems.length;
let $icon = $w("#"+id);
if (count) $icon.show();
else $icon.hide();
}
}