Hide shopping cart when empty - Wix Stores

Heyas,

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. :slight_smile:

2 Likes

Hi,
I’m afraid that currently there’s no integration of Wix Code with Wix Stores. However this is on our backlog.

Have a good day,
Tal.

I need to hide the shopping too. Is it possible to hide it on certain pages like my homepage all together?

Has this been added yet? Would be great to hide the empty cart!

it’s 2021 now. can we have this yet?

We really need this as well.

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();
    }
}
1 Like