All Categories Troubleshooting Resolve Add to Cart Issues on Your Wix Store

Resolve Add to Cart Issues on Your Wix Store

If products on your Wix store aren’t being added to the cart when using Appsell, it’s usually due to a small conflict with your site’s theme or custom scripts. This guide will walk you through adding a short custom code snippet to fix the issue - covering both Wix Studio and Wix Editor users.


For Wix Studio users:

  1. Login to your Wix admin

  2. Edit your site using the Studio Editor.

  3. Click on the "{ }" icon on the left side bar and select the MasterPage.js file from the list

  4. Copy and paste the script below inside the script editor area.

  5. Publish the changes.

    studio.png

    Copy and paste this script:

import { cart } from 'wix-stores-frontend';
        import {local} from 'wix-storage-frontend';

        $w.onReady(function () 
        {
            cart.getCurrentCart()
            .then((currentCart) => {
                if (currentCart && currentCart._id && currentCart._id != "00000000-000000-000000-000000000000")
                {
                    const cartId = currentCart._id;
                    local.setItem('appsell_cart', cartId);
                }
                else{
                    const products = [
                        {
                            "productId": "tmp_product_id",
                            "quantity": 1,
                            "options":{
                                "choices" : {"Color.": "Orange"} 
                            }
                        }
                    ];

                    addProductToCart(products);
                }
            })
            .catch((error) => {
                console.error(error);
            });

            cart.onChange((changedCart) => {
                const cartId = changedCart._id;
                local.setItem('appsell_cart', cartId);
            });

            function addProductToCart(products) {
                cart.addProducts(products)
                    .then((updatedCart) => {
                        // Products added to cart
                        const cartId = updatedCart._id;
                        local.setItem('appsell_cart', cartId);
                    })
                    .catch((error) => {
                        // Products not added to cart
                        console.error(error);
                    });
            }
        });

Very important: Once you're done, Make sure to Publish the changes otherwise they won't take effect.


For Wix Editor users:

  1. Login to your Wix admin

  2. Edit your site using the Editor.

  3. Click on "Dev mode" and "Turn on Dev mode"

Dev-mode.png

  1. Once Dev mode is enabled, select MasterPage.js from the list and copy paste the following script in the script editor area.

  2. Publish the changes.

master2.png

Copy and paste this script:

import { cart } from 'wix-stores-frontend';
        import {local} from 'wix-storage-frontend';

        $w.onReady(function () 
        {
            cart.getCurrentCart()
            .then((currentCart) => {
                if (currentCart && currentCart._id && currentCart._id != "00000000-000000-000000-000000000000")
                {
                    const cartId = currentCart._id;
                    local.setItem('appsell_cart', cartId);
                }
                else{
                    const products = [
                        {
                            "productId": "tmp_product_id",
                            "quantity": 1,
                            "options":{
                                "choices" : {"Color.": "Orange"} 
                            }
                        }
                    ];

                    addProductToCart(products);
                }
            })
            .catch((error) => {
                console.error(error);
            });

            cart.onChange((changedCart) => {
                const cartId = changedCart._id;
                local.setItem('appsell_cart', cartId);
            });

            function addProductToCart(products) {
                cart.addProducts(products)
                    .then((updatedCart) => {
                        // Products added to cart
                        const cartId = updatedCart._id;
                        local.setItem('appsell_cart', cartId);
                    })
                    .catch((error) => {
                        // Products not added to cart
                        console.error(error);
                    });
            }
        });

Very important: Once you're done, Make sure to Publish the changes otherwise they won't take effect.

Was this article helpful?

Thanks for your feedback!