Close cart go back to top of the page

Hello,

When I add an item to the cart, and close the cart, view goes back to the top of the page. Everytime.

Also, can you let me know how I can display the item quantity I have in my cart ? The number don’t show off.

Can you please let me know how to fix that ? Thanks a lot !

Read-only link : https://preview.webflow.com/preview/hereticcoffee?utm_medium=preview_link&utm_source=designer&utm_content=hereticcoffee&preview=e1424927a9c764fb8378d4b519b61de3&workflow=preview

Have a great day,
Théo

Hello, up. Can someone help ?

Up, please any solution ?

Can someone help ? Would love to have a solution :slight_smile:

Hello, is it possible to have a solution ? Or something I should try ? Thanks.

Tvog, were you able to figure this out? Struggling with the same issue and sad to see nobody answered your responses thus far. Would appreciate any help :handshake:

I’ve figured it out

document.addEventListener('DOMContentLoaded', function() {
    let savedScrollPosition = 0;
    const cartWrapper = document.querySelector('.w-commerce-commercecartwrapper');

    if (!cartWrapper) {
        console.error('Cart wrapper not found');
        return;
    }

    function handleCartStateChange(mutations) {
        for (let mutation of mutations) {
            if (mutation.type === 'attributes' && mutation.attributeName === 'data-cart-open') {
                const isCartOpen = cartWrapper.getAttribute('data-cart-open') !== null;
                
                if (isCartOpen) {
                    console.log('Cart has opened');
                    savedScrollPosition = window.pageYOffset;
                    console.log('Body scroll position:', savedScrollPosition);
                    document.body.style.top = `-${savedScrollPosition}px`;
                    document.body.style.position = 'fixed';
                    document.body.style.width = '100%';
                } else {
                    console.log('Cart has closed');
                    document.body.style.position = '';
                    document.body.style.top = '';
                    document.body.style.width = '';
                    window.scrollTo(0, savedScrollPosition);
                    console.log('Scroll action has fired');
                }
            }
        }
    }

    const observer = new MutationObserver(handleCartStateChange);
    observer.observe(cartWrapper, { attributes: true, attributeFilter: ['data-cart-open'] });
});

Also having same issue, I still have not found a solution yet. Sad that the Webflow team has not responded since this question was asked since Aug 2022!!!

Hi Shalom, this is a community forum, the Webflow team doesn’t generally message here. You should open a ticket with support when you cannot find a solution here.

You should obviously try the solution just above, first.