Note:
The wix-stores-frontend.Cart
modules is deprecated.
If you're already using this modules in your code, it will continue to work.
To stay compatible with future changes, update your code
with the migration instructions in this module's functions.
The wix-stores-frontend.Cart
module contains functionality for working with your
site's cart from client-side code.
To use the Wix Stores Cart API, import { cart }
from the wix-stores-frontend
module:
import { cart } from "wix-stores-frontend";
Deprecated.
This function will continue to work, but a newer version is available at
wix-ecom-backend.currentCart.addToCurrentCart()
.
If this function is already in your code, it will continue to work.
To stay compatible with future changes, migrate to
wix-ecom-backend.currentCart.addToCurrentCart()
.
To migrate to the new function:
Add the new import statement:
import { currentCart } from "wix-ecom-backend";
Look for any code that uses cart.addProducts()
,
and replace it with currentCart.addToCurrentCart()
.
Update your code to work with the new currentCart.addToCurrentCart()
call and response properties.
To help with updating your code to work with the new currentCart.addToCurrentCart()
properties, learn more about integrating Wix Stores with the Wix eCommerce.
Test your changes to make sure your code behaves as expected.
Adds one or more products to the cart.
The addProducts()
function returns a Promise that is resolved when the
specified products are added to the cart.
Use the quantity
property of each AddToCartItem
object that is
passed to the products parameter to add one or more products to the cart at one time.
Use the options
property of each AddToCartItem
object that is
passed to the products parameter to specify the product options to choose when adding
the product to the cart. For example, if a product comes in different sizes, you can
specify the size that should be added to the cart. If the product you are adding to the
cart has options, you must specify which options should be chosen.
You can see a product's option information in the productOptions
field in the Stores/Products collection.
You can use product.getOptionsAvailability()
to determine if an item with specific options is available for purchase.
Note: If you use wix-stores-backend.createProduct()
immediately before adding that product to the cart, we suggest setting a timeout for "1000"
milliseconds (1 second) before calling cart.addProducts()
. While this slows down the operation slightly, it also ensures proper retrieval of the newly created product before adding it to the cart.
function addProducts(products: Array<AddToCartItem>): Promise<CartObj>;
One or more products to be added to the cart.
This example uses a deprecated function.
import { cart } from "wix-stores-frontend";
const products = [
{
productId: "0873ed58-f88d-77d1-4566-afd4c50d253e",
quantity: 3,
},
{
productId: "91f7ac8b-2baa-289c-aa50-6d64764f35d3",
quantity: 1,
options: {
choices: {
Weight: "250g",
"Ground for": "Filter",
},
},
},
{
productId: "5376f9ec-b92e-efa9-e4a1-f4f480aa0d3a",
quantity: 1,
options: {
choices: {
Weight: "500g",
"Ground for": "Stovetop",
},
customTextFields: [
{
title: "Custom package sticker",
value: "Enjoy your coffee!",
},
],
},
},
];
cart
.addProducts(products)
.then((updatedCart) => {
// Products added to cart
const cartId = updatedCart._id;
const cartLineItems = updatedCart.lineItems;
})
.catch((error) => {
// Products not added to cart
console.error(error);
});
/* Example of returned updatedCart object:
*
* {
* "_id": "5d54aa6f-f653-4bed-8c34-7f1373f88c89",
* "status": "INCOMPLETE",
* "billingAddress": {
* "firstName": "Jane",
* "lastName": "Doe",
* "email": "",
* "phone": "+1234567890",
* "company": "undefined",
* "vatId": "undefined",
* "address": "235 West 23rd Street\nNew York, New York 10011\nUnited States"
* },
* "appliedCoupon": "null",
* "buyerInfo": {
* "email": "",
* "firstName": "Jane",
* "identityType": "ADMIN",
* "lastName": "Doe",
* "phone": "+1234567890"
* },
* "buyerNote": "undefined",
* "currency": {
* "symbol": "$",
* "code": "USD"
* },
* "lineItems": [
* {
* "id": 16,
* "productId": "0873ed58-f88d-77d1-4566-afd4c50d253e",
* "name": "Digital product",
* "quantity": 3,
* "lineItemType": "DIGITAL",
* "customTextFields": [],
* "options": [],
* "price": 20,
* "totalPrice": 60,
* "mediaItem": "null",
* "weight": 0
* },
* {
* "id": 17,
* "productId": "91f7ac8b-2baa-289c-aa50-6d64764f35d3",
* "name": "Colombian Arabica",
* "quantity": 1,
* "weight": 0.25,
* "sku": "10003",
* "lineItemType": "PHYSICAL",
* "customTextFields": [],
* "mediaItem": {
* "src": "wix:image://v1/nsplsh_5033504669385448625573~mv2_d_6000_3376_s_4_2.jpg/file.jpg#originWidth=6000&originHeight=3376",
* "type": "IMAGE"
* },
* "options": [
* {
* "option": "Weight",
* "selection": "250g"
* },
* {
* "option": "Ground for",
* "selection": "Filter"
* }
* ],
* "price": 35,
* "totalPrice": 35
* },
* {
* "id": 18,
* "productId": "5376f9ec-b92e-efa9-e4a1-f4f480aa0d3a",
* "name": "Indonesian Blend",
* "quantity": 1,
* "lineItemType": "PHYSICAL",
* "customTextFields": [
* {
* "title": "Custom package sticker",
* "value": "Enjoy your coffee!"
* }
* ],
* "mediaItem": {
* "src": "wix:image://v1/nsplsh_316b6449475f3235386255~mv2_d_2977_3951_s_4_2.jpg/file.jpg#originWidth=2977&originHeight=3951",
* "type": "IMAGE"
* },
* "options": [
* {
* "option": "Weight",
* "selection": "500g"
* },
* {
* "option": "Ground for",
* "selection": "Stovetop"
* }
* ],
* "price": 35,
* "totalPrice": 35,
* "weight": 0
* }
* ],
* "shippingInfo": {
* "shippingAddress": {
* "firstName": "Jane",
* "lastName": "Doe",
* "email": "",
* "phone": "+1234567890",
* "company": "undefined",
* "vatId": "undefined",
* "address": "235 West 23rd Street\nNew York, New York 10011\nUnited States"
* }
* },
* "totals": {
* "discount": 0,
* "quantity": 5,
* "shipping": 0,
* "subtotal": 160,
* "tax": 0,
* "total": 160,
* "weight": 0.75
* },
* "weightUnit": "KG"
* }
*
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Deprecated.
This function will continue to work, but a newer version is available at
wix-ecom-backend.currentCart.updateCurrentCart()
.
If this function is already in your code, it will continue to work.
To stay compatible with future changes, migrate to
wix-ecom-backend.currentCart.updateCurrentCart()
.
To migrate to the new function:
Add the new import statement:
import { currentCart } from "wix-ecom-backend";
Look for any code that uses cart.applyCoupon()
,
and replace it with currentCart.updateCurrentCart()
.
Update your code to work with the new currentCart.updateCurrentCart()
call and response properties.
Test your changes to make sure your code behaves as expected.
Adds and applies a coupon to the cart.
The applyCoupon()
function returns a Promise that resolves to the current
site visitor's cart when the specified coupon has been applied.
The cart can only hold one coupon. If a coupon is already applied to the cart, passing a different couponCode
to applyCoupon()
will replace the existing one.
Note: When editing a site as a contributor, applyCoupon()
will only work when viewing the live site.
function applyCoupon(couponCode: string): Promise<CartObj>;
The code of the coupon to be applied to the cart.
This example uses a deprecated function.
import { cart } from "wix-stores-frontend";
const couponCode = "SummerSale";
cart
.applyCoupon(couponCode)
.then((updatedCart) => {
const couponDiscount = updatedCart.appliedCoupon.discountValue;
})
.catch((error) => {
console.error(error);
});
/* Example of returned updatedCart object:
*
* {
* "_id": "b36eb035-635a-450e-b74d-acf86ee4dfcc",
* "appliedCoupon": {
* "couponId": "e81e9c48-f954-4044-ba64-ccfe5c103c8f",
* "name": "Summer Sale",
* "code": "SummerSale",
* "discountValue": "$10.00",
* "couponType": "MoneyOff"
* },
* "billingAddress": {
* "firstName": "John",
* "lastName": "Doe",
* "email":"john.doe@somedomain.com",
* "phone":"5555555",
* "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"
* },
* "buyerNote": "This is a note from the buyer.",
* "buyerInfo":{
* "firstName": "John",
* "lastName": "Doe",
* "email": "john.doe@somedomain.com",
* "phone": "5555555555",
* "identityType": "CONTACT"
* },
* "status": "INCOMPLETE",
* "currency": {
* "code": "USD",
* "symbol": "$"
* },
* "shippingInfo": {
* "deliveryOption": "Free Shipping",
* "shippingAddress": {
* "firstName": "John",
* "lastName": "Doe",
* "email":"john.doe@somedomain.com",
* "phone":"5555555",
* "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"
* },
* "pickupDetails":null
* },
* "lineItems":[
* {
* "quantity": 1,
* "price": 120,
* "name": "A product",
* "productId": "a668ef33-f5b8-6569-d04c-1d123be68441",
* "totalPrice": 120,
* "lineItemType": "PHYSICAL",
* "customTextFields": [
* "title": "Custom Field",
* "value": "Custom value"
* ],
* "mediaItem": {
* "src": "wix:image://v1/a9ff3b_ed3b544c319b4fad9c222c791a997832.jpg/file.jpg#originWidth=1000&originHeight=1000",
* "type": "IMAGE"
* },
* "sku": "21554345656",
* "options": [ ],
* "weight": 3,
* "id": 1
* },
* {
* "quantity": 1,
* "price": 25,
* "name": "Another product",
* "productId": "1a2d7e83-4bef-31d5-09e1-3326ee271c09",
* "totalPrice": 25,
* "lineItemType": "PHYSICAL",
* "mediaItem": {
* "src": "wix:image://v1/a9ff3b_c6158b4d41784ae8b08337a331e1de7f.jpg/file.jpg#originWidth=1000&originHeight=1000",
* "type": "IMAGE"
* },
* "sku": "217537123517253",
* "options": [
* {
* "option": "Size",
* "selection": "Medium"
* },
* {
* "option": "Color",
* "selection": "Black"
* }
* ],
* "weight": 2,
* "id": 2
* }
* ],
* "totals": {
* "discount": 10,
* "quantity": 2,
* "shipping": 0,
* "subtotal": 145,
* "tax": 0,
* "total": 135,
* "weight": 5
* },
* "weightUnit": "LB"
* }
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Deprecated.
This function will continue to work, but a newer version is available at
wix-ecom-backend.CurrentCart.getCurrentCart()
.
We recommend you migrate to the new Wix eCommerce APIs as soon as possible.
If this function is already in your code, it will continue to work.
To stay compatible with future changes, migrate to
wix-ecom-backend.CurrentCart.getCurrentCart()
.
The wix-ecom-backend.CurrentCart.getCurrentCart()
function works from both backend and frontend code.
To migrate to the new function:
Add the new import statement:
import { currentCart } from "wix-ecom-backend";
Look for any code that uses cart.getCurrentCart()
,
and replace it with currentCart.getCurrentCart()
.
Update your code to work with the new currentCart.getCurrentCart()
call and response properties.
For more info about the differences between the Stores Cart and eCommerce Cart, refer to the cart conversion table.
Test your changes to make sure your code behaves as expected.
Gets the current site visitor's shopping cart.
The getCurrentCart()
function returns a Promise that resolves to the current
site visitor's shopping cart.
function getCurrentCart(): Promise<CartObj>;
This example uses a deprecated function.
import { cart } from "wix-stores-frontend";
cart
.getCurrentCart()
.then((currentCart) => {
const cartId = currentCart._id;
const cartLineItems = currentCart.lineItems;
})
.catch((error) => {
console.error(error);
});
/* Example of returned currentCart object:
*
* {
* "_id": "b36eb035-635a-450e-b74d-acf86ee4dfcc",
* "appliedCoupon": {
* "couponId": "e81e9c48-f954-4044-ba64-ccfe5c103c8f",
* "name": "Summer Sale",
* "code": "SummerSale",
* "discountValue": "$10.00",
* "couponType": "MoneyOff"
* },
* "billingAddress": {
* "firstName": "John",
* "lastName": "Doe",
* "email":"john.doe@somedomain.com",
* "phone":"5555555",
* "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"
* },
* "buyerNote": "This is a note from the buyer.",
* "buyerInfo":{
* "firstName": "John",
* "lastName": "Doe",
* "email": "john.doe@somedomain.com",
* "phone": "5555555555",
* "identityType": "CONTACT"
* },
* "status": "INCOMPLETE",
* "currency": {
* "code": "USD"
* },
* "shippingInfo": {
* "deliveryOption": "Free Shipping",
* "shippingAddress": {
* "firstName": "John",
* "lastName": "Doe",
* "email":"john.doe@somedomain.com",
* "phone":"5555555",
* "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"
* },
* "pickupDetails":null
* },
* "lineItems":[
* {
* "quantity": 1,
* "price": 120,
* "name": "A product",
* "productId": "a668ef33-f5b8-6569-d04c-1d123be68441",
* "totalPrice": 120,
* "lineItemType": "PHYSICAL",
* "customTextFields": [
* "title": "Custom Field",
* "value": "Custom value"
* ],
* "mediaItem": {
* "src": "wix:image://v1/a9ff3b_ed3b544c319b4fad9c222c791a997832.jpg/file.jpg#originWidth=1000&originHeight=1000",
* "type": "IMAGE"
* },
* "sku": "21554345656",
* "options": [ ],
* "weight": 3,
* "id": 1
* },
* {
* "quantity": 1,
* "price": 25,
* "name": "Another product",
* "productId": "1a2d7e83-4bef-31d5-09e1-3326ee271c09",
* "totalPrice": 25,
* "lineItemType": "PHYSICAL",
* "mediaItem": {
* "src": "wix:image://v1/a9ff3b_c6158b4d41784ae8b08337a331e1de7f.jpg/file.jpg#originWidth=1000&originHeight=1000",
* "type": "IMAGE"
* },
* "sku": "217537123517253",
* "options": [
* {
* "option": "Size",
* "selection": "Medium"
* },
* {
* "option": "Color",
* "selection": "Black"
* }
* ],
* "weight": 2,
* "id": 2
* }
* ],
* "totals": {
* "discount": 0,
* "quantity": 2,
* "shipping": 0,
* "subtotal": 145,
* "tax": 0,
* "total": 145,
* "weight": 5
* },
* "weightUnit": "LB"
* }
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Deprecated. This function will continue to work, but will soon be deprecated. Hiding the Mini Cart or Side Cart can be done by clicking anywhere else on the page.
Hides the Mini Cart.
The hideMiniCart()
function hides the Mini Cart.
Learn more about the Mini Cart.
Note: This API will fail when viewing the site on mobile because there is no Mini Cart on the mobile site.
function hideMiniCart(): void;
This example uses a deprecated function. Add products to the cart, then show the Mini Cart. After 3 seconds, hide the Mini Cart.
import { cart } from "wix-stores-frontend";
import { formFactor } from "wix-window-frontend";
const products = [
{
productId: "0873ed58-f88d-77d1-4566-afd4c50d253e",
quantity: 2,
},
];
cart
.addProducts(products)
.then(() => {
// Only show the Mini Cart if the site is not being viewed on mobile
if (formFactor !== "Mobile") {
cart.showMiniCart();
// After displaying the Mini Cart for 3 seconds, hide the Mini Cart
setTimeout(() => cart.hideMiniCart(), 3000);
}
})
.catch((error) => {
console.error(error);
});
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Deprecated.
This function will continue to work, but a newer version is available at
wix-ecom-frontend.onCartChange()
.
If this function is already in your code, it will continue to work.
To stay compatible with future changes, migrate to
wix-ecom-frontend.onCartChange()
.
To migrate to the new function:
Add the new import statement:
import wixEcomFrontend from "wix-ecom-frontend";
Look for any code that uses cart.onChange()
,
and replace it with wixEcomFrontend.onCartChange()
.
The new onCartChange()
event handler does not return the changed cart. Update your code accordingly.
Test your changes to make sure your code behaves as expected.
An event handler that is triggered when items are added or removed from a cart.
The onChange()
function is a client-side event handler invoked every time the cart changes. It takes a callback function which receives the new Cart
object as a parameter.
Notes:
onChange()
in the global site code file (masterPage.js). This ensures the event is triggered when a change to the cart is made on any page. Learn more about global (site) code.onChange()
function can only be used once a page has loaded. Therefore, you must use it in code that is contained in or is called from the onReady() event handler or any element event handler.onChange()
will only work when viewing the live site.function onChange(handler: function): void;
handler(cart: CartObj): void
The name of the function to run when a cart changes.
This example uses a deprecated function.
/************************************
* Global (Site) code (masterPage.js) *
************************************/
import { cart } from "wix-stores-frontend";
$w.onReady(function () {
cart.onChange((changedCart) => {
const cartId = changedCart._id;
const cartLineItems = changedCart.lineItems;
});
});
/* Example of returned changedCart object:
*
* {
* "_id": "b36eb035-635a-450e-b74d-acf86ee4dfcc",
* "appliedCoupon": {
* "couponId": "e81e9c48-f954-4044-ba64-ccfe5c103c8f",
* "name": "Summer Sale",
* "code": "SummerSale",
* "discountValue": "$10.00",
* "couponType": "MoneyOff"
* },
* "billingAddress": {
* "firstName": "John",
* "lastName": "Doe",
* "email":"john.doe@somedomain.com",
* "phone":"5555555",
* "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"
* },
* "buyerNote": "This is a note from the buyer.",
* "buyerInfo":{
* "firstName": "John",
* "lastName": "Doe",
* "email": "john.doe@somedomain.com",
* "phone": "5555555555",
* "identityType": "CONTACT"
* },
* "status": "INCOMPLETE",
* "currency": {
* "code": "USD",
* "symbol": "$"
* },
* "shippingInfo": {
* "deliveryOption": "Free Shipping",
* "shippingAddress": {
* "firstName": "John",
* "lastName": "Doe",
* "email":"john.doe@somedomain.com",
* "phone":"5555555",
* "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"
* },
* "pickupDetails":null
* },
* "lineItems":[
* {
* "quantity": 1,
* "price": 120,
* "name": "A product",
* "productId": "a668ef33-f5b8-6569-d04c-1d123be68441",
* "totalPrice": 120,
* "lineItemType": "PHYSICAL",
* "customTextFields": [
* "title": "Custom Field",
* "value": "Custom value"
* ],
* "mediaItem": {
* "src": "wix:image://v1/a9ff3b_ed3b544c319b4fad9c222c791a997832.jpg/file.jpg#originWidth=1000&originHeight=1000",
* "type": "IMAGE"
* },
* "sku": "21554345656",
* "options": [ ],
* "weight": 3,
* "id": 1
* },
* {
* "quantity": 1,
* "price": 25,
* "name": "Another product",
* "productId": "1a2d7e83-4bef-31d5-09e1-3326ee271c09",
* "totalPrice": 25,
* "lineItemType": "PHYSICAL",
* "mediaItem": {
* "src": "wix:image://v1/a9ff3b_c6158b4d41784ae8b08337a331e1de7f.jpg/file.jpg#originWidth=1000&originHeight=1000",
* "type": "IMAGE"
* },
* "sku": "217537123517253",
* "options": [
* {
* "option": "Size",
* "selection": "Medium"
* },
* {
* "option": "Color",
* "selection": "Black"
* }
* ],
* "weight": 2,
* "id": 2
* }
* ],
* "totals": {
* "discount": 0,
* "quantity": 2,
* "shipping": 0,
* "subtotal": 145,
* "tax": 0,
* "total": 145,
* "weight": 5
* },
* "weightUnit": "LB"
* }
*
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Deprecated.
This function will continue to work, but a newer version is available at
wix-ecom-backend.currentCart.removeCouponFromCurrentCart()
.
If this function is already in your code, it will continue to work.
To stay compatible with future changes, migrate to
wix-ecom-backend.currentCart.removeCouponFromCurrentCart()
.
To migrate to the new function:
Add the new import statement:
import { currentCart } from "wix-ecom-backend";
Look for any code that uses cart.removeCoupon()
,
and replace it with currentCart.removeCouponFromCurrentCart()
.
Update your code to work with the new currentCart.removeCouponFromCurrentCart()
call and response properties.
Test your changes to make sure your code behaves as expected.
Removes the coupon currently applied to the cart.
The removeCoupon()
function returns a Promise that resolves to the current
site visitor's cart when the currently applied coupon has been removed.
Note: When editing a site as a contributor, removeCoupon()
will only work when viewing the live site.
function removeCoupon(): Promise<CartObj>;
This example uses a deprecated function.
import { cart } from "wix-stores-frontend";
cart
.removeCoupon()
.then((updatedCart) => {
const cartId = updatedCart._id;
const cartLineItems = updatedCart.lineItems;
})
.catch((error) => {
console.error(error);
});
/* Example of returned updatedCart object:
*
* {
* "_id": "b36eb035-635a-450e-b74d-acf86ee4dfcc",
* "appliedCoupon": "null",
* "billingAddress": {
* "firstName": "John",
* "lastName": "Doe",
* "email":"john.doe@somedomain.com",
* "phone":"5555555",
* "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"
* },
* "buyerNote": "This is a note from the buyer.",
* "buyerInfo":{
* "firstName": "John",
* "lastName": "Doe",
* "email": "john.doe@somedomain.com",
* "phone": "5555555555",
* "identityType": "CONTACT"
* },
* "status": "INCOMPLETE",
* "currency": {
* "code": "USD",
* "symbol": "$"
* },
* "shippingInfo": {
* "deliveryOption": "Free Shipping",
* "shippingAddress": {
* "firstName": "John",
* "lastName": "Doe",
* "email":"john.doe@somedomain.com",
* "phone":"5555555",
* "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"
* },
* "pickupDetails":null
* },
* "lineItems":[
* {
* "quantity": 1,
* "price": 120,
* "name": "A product",
* "productId": "a668ef33-f5b8-6569-d04c-1d123be68441",
* "totalPrice": 120,
* "lineItemType": "PHYSICAL",
* "customTextFields": [
* "title": "Custom Field",
* "value": "Custom value"
* ],
* "mediaItem": {
* "src": "wix:image://v1/a9ff3b_ed3b544c319b4fad9c222c791a997832.jpg/file.jpg#originWidth=1000&originHeight=1000",
* "type": "IMAGE"
* },
* "sku": "21554345656",
* "options": [ ],
* "weight": 3,
* "id": 1
* },
* {
* "quantity": 1,
* "price": 25,
* "name": "Another product",
* "productId": "1a2d7e83-4bef-31d5-09e1-3326ee271c09",
* "totalPrice": 25,
* "lineItemType": "PHYSICAL",
* "mediaItem": {
* "src": "wix:image://v1/a9ff3b_c6158b4d41784ae8b08337a331e1de7f.jpg/file.jpg#originWidth=1000&originHeight=1000",
* "type": "IMAGE"
* },
* "sku": "217537123517253",
* "options": [
* {
* "option": "Size",
* "selection": "Medium"
* },
* {
* "option": "Color",
* "selection": "Black"
* }
* ],
* "weight": 2,
* "id": 2
* }
* ],
* "totals": {
* "discount": 0,
* "quantity": 2,
* "shipping": 0,
* "subtotal": 145,
* "tax": 0,
* "total": 145,
* "weight": 5
* },
* "weightUnit": "LB"
* }
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Deprecated.
This function will continue to work, but a newer version is available at
wix-ecom-backend.currentCart.removeLineItemsFromCurrentCart()
.
If this function is already in your code, it will continue to work.
To stay compatible with future changes, migrate to
wix-ecom-backend.currentCart.removeLineItemsFromCurrentCart()
.
To migrate to the new function:
Add the new import statement:
import { currentCart } from "wix-ecom-backend";
Look for any code that uses cart.removeProduct()
,
and replace it with currentCart.removeLineItemsFromCurrentCart()
.
Update your code to work with the new currentCart.removeLineItemsFromCurrentCart()
call and response properties.
Test your changes to make sure your code behaves as expected.
Removes a specified product from the cart.
The removeProduct()
function returns a Promise that resolves to the
updated cart after the product is removed.
Every line item in a cart has an ID. Pass this to removeProduct()
to remove that line item/product from the cart.
Notes:
removeProduct()
does not decrement the line item's quantity, it removes the line item/product altogether.removeProduct()
will only work when viewing the live site.function removeProduct(cartLineItemId: number): Promise<CartObj>;
ID of the cart line item to remove.
This example uses a deprecated function.
import { cart } from "wix-stores-frontend";
const cartLineItemId = 3;
cart
.removeProduct(cartLineItemId)
.then((updatedCart) => {
// Product successfully removed
const cartLineItems = updatedCart.lineItems;
})
.catch((error) => {
// Product not removed
console.error(error);
});
/* Example of returned updatedCart:
*
* {
* "_id": "b36eb035-635a-450e-b74d-acf86ee4dfcc",
* "appliedCoupon": {
* "couponId": "e81e9c48-f954-4044-ba64-ccfe5c103c8f",
* "name": "Summer Sale",
* "code": "SummerSale",
* "discountValue": "$10.00",
* "couponType": "MoneyOff"
* },
* "billingAddress": {
* "firstName": "John",
* "lastName": "Doe",
* "email":"john.doe@somedomain.com",
* "phone":"5555555",
* "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"
* },
* "buyerNote": "This is a note from the buyer.",
* "buyerInfo":{
* "firstName": "John",
* "lastName": "Doe",
* "email": "john.doe@somedomain.com",
* "phone": "5555555555",
* "identityType": "CONTACT"
* },
* "status": "INCOMPLETE",
* "currency": {
* "code": "USD",
* "symbol": "$"
* },
* "shippingInfo": {
* "deliveryOption": "Free Shipping",
* "shippingAddress": {
* "firstName": "John",
* "lastName": "Doe",
* "email":"john.doe@somedomain.com",
* "phone":"5555555",
* "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"
* },
* "pickupDetails":null
* },
* "lineItems":[
* {
* "quantity": 1,
* "price": 120,
* "name": "A product",
* "productId": "a668ef33-f5b8-6569-d04c-1d123be68441",
* "totalPrice": 120,
* "lineItemType": "PHYSICAL",
* "customTextFields": [
* "title": "Custom Field",
* "value": "Custom value"
* ],
* "mediaItem": {
* "src": "wix:image://v1/a9ff3b_ed3b544c319b4fad9c222c791a997832.jpg/file.jpg#originWidth=1000&originHeight=1000",
* "type": "IMAGE"
* },
* "sku": "21554345656",
* "options": [ ],
* "weight": 3,
* "id": 1
* },
* {
* "quantity": 1,
* "price": 25,
* "name": "Another product",
* "productId": "1a2d7e83-4bef-31d5-09e1-3326ee271c09",
* "totalPrice": 25,
* "lineItemType": "PHYSICAL",
* "mediaItem": {
* "src": "wix:image://v1/a9ff3b_c6158b4d41784ae8b08337a331e1de7f.jpg/file.jpg#originWidth=1000&originHeight=1000",
* "type": "IMAGE"
* },
* "sku": "217537123517253",
* "options": [
* {
* "option": "Size",
* "selection": "Medium"
* },
* {
* "option": "Color",
* "selection": "Black"
* }
* ],
* "weight": 2,
* "id": 2
* }
* ],
* "totals": {
* "discount": 0,
* "quantity": 2,
* "shipping": 0,
* "subtotal": 145,
* "tax": 0,
* "total": 145,
* "weight": 5
* },
* "weightUnit": "LB"
* }
*
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Deprecated.
This function will continue to work, but a newer version is available at
wix-ecom-frontend.openSideCart()
.
If this function is already in your code, it will continue to work.
To stay compatible with future changes, migrate to
wix-ecom-frontend.openSideCart()
.
To migrate to the new function:
Add the new import statement:
import wixEcomFrontend from "wix-ecom-frontend";
Look for any code that uses cart.showMiniCart()
,
and replace it with wixEcomFrontend.openSideCart()
.
Test your changes to make sure your code behaves as expected.
Shows the Mini Cart.
The showMiniCart()
function displays the Mini Cart.
Learn more about the Mini Cart.
Note: This API will fail when viewing the site on mobile because there is no Mini Cart on the mobile site.
function showMiniCart(): void;
This example uses a deprecated function.
import { cart } from "wix-stores-frontend";
import { formFactor } from "wix-window-frontend";
const products = [
{
productId: "0873ed58-f88d-77d1-4566-afd4c50d253e",
quantity: 2,
},
];
cart
.addProducts(products)
.then(() => {
// Only show the Mini Cart if the site is not being viewed on mobile
if (formFactor !== "Mobile") {
cart.showMiniCart();
}
})
.catch((error) => {
console.error(error);
});
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Deprecated.
This function will continue to work, but a newer version is available at
wix-ecom-backend.currentCart.updateCurrentCartLineItemQuantity()
.
If this function is already in your code, it will continue to work.
To stay compatible with future changes, migrate to
wix-ecom-backend.currentCart.updateCurrentCartLineItemQuantity()
.
To migrate to the new function:
Add the new import statement:
import { currentCart } from "wix-ecom-backend";
Look for any code that uses cart.updateLineItemQuantity()
,
and replace it with currentCart.updateCurrentCartLineItemQuantity()
.
Update your code to work with the new currentCart.updateCurrentCartLineItemQuantity()
call and response properties.
Updates the quantity of a specified line item in the cart.
The updateLineItemQuantity()
function returns a Promise that resolves to the current
site visitor's cart when the specified line item's quantity has been updated.
Note: When editing a site as a contributor, updateLineItemQuantity()
will only work when viewing the live site.
function updateLineItemQuantity(
cartLineItemId: number,
quantity: number,
): Promise<CartObj>;
ID of the cart line item to update.
Line item's new quantity.
This example uses a deprecated function.
import { cart } from "wix-stores-frontend";
const cartLineItemId = 2;
const quantity = 10;
cart
.updateLineItemQuantity(cartLineItemId, quantity)
.then((updatedCart) => {
// Cart line item's quantity updated
const cartId = updatedCart._id;
const updatedLineItems = updatedCart.lineItems;
})
.catch((error) => {
// Cart line item's quantity not updated
console.log(error);
});
/* Example of returned updatedCart object:
*
* {
* "_id": "b36eb035-635a-450e-b74d-acf86ee4dfcc",
* "appliedCoupon": {
* "couponId": "e81e9c48-f954-4044-ba64-ccfe5c103c8f",
* "name": "Summer Sale",
* "code": "SummerSale",
* "discountValue": "$10.00",
* "couponType": "MoneyOff"
* },
* "billingAddress": {
* "firstName": "John",
* "lastName": "Doe",
* "email":"john.doe@somedomain.com",
* "phone":"5555555",
* "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"
* },
* "buyerNote": "This is a note from the buyer.",
* "buyerInfo":{
* "firstName": "John",
* "lastName": "Doe",
* "email": "john.doe@somedomain.com",
* "phone": "5555555555",
* "identityType": "CONTACT"
* },
* "status": "INCOMPLETE",
* "currency": {
* "code": "USD",
* "symbol": "$"
* },
* "shippingInfo": {
* "deliveryOption": "Free Shipping",
* "shippingAddress": {
* "firstName": "John",
* "lastName": "Doe",
* "email":"john.doe@somedomain.com",
* "phone":"5555555",
* "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"
* },
* "pickupDetails":null
* },
* "lineItems":[
* {
* "quantity": 1,
* "price": 120,
* "name": "A product",
* "productId": "a668ef33-f5b8-6569-d04c-1d123be68441",
* "totalPrice": 120,
* "lineItemType": "PHYSICAL",
* "customTextFields": [
* "title": "Custom Field",
* "value": "Custom value"
* ],
* "mediaItem": {
* "src": "wix:image://v1/a9ff3b_ed3b544c319b4fad9c222c791a997832.jpg/file.jpg#originWidth=1000&originHeight=1000",
* "type": "IMAGE"
* },
* "sku": "21554345656",
* "options": [ ],
* "weight": 3,
* "id": 1
* },
* {
* "quantity": 10,
* "price": 25,
* "name": "Another product",
* "productId": "1a2d7e83-4bef-31d5-09e1-3326ee271c09",
* "totalPrice": 25,
* "lineItemType": "PHYSICAL",
* "mediaItem": {
* "src": "wix:image://v1/a9ff3b_c6158b4d41784ae8b08337a331e1de7f.jpg/file.jpg#originWidth=1000&originHeight=1000",
* "type": "IMAGE"
* },
* "sku": "217537123517253",
* "options": [
* {
* "option": "Size",
* "selection": "Medium"
* },
* {
* "option": "Color",
* "selection": "Black"
* }
* ],
* "weight": 2,
* "id": 2
* }
* ],
* "totals": {
* "discount": 0,
* "quantity": 2,
* "shipping": 0,
* "subtotal": 145,
* "tax": 0,
* "total": 145,
* "weight": 5
* },
* "weightUnit": "LB"
* }
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.