Introduction

Note: This module is universal. Functions in this module can run on both the backend and frontend.

The Current Cart API provides functionality for managing the current site visitor's cart and creating a checkout based on the current cart.

A cart object is created whenever a product or service is added to the current cart, or the cart.createCart() function is called.

The cart is the first phase of an eCommerce purchase flow, followed by checkout, then order. A cart holds information about items for purchase, prices, discounts, site details, and more.

The Current Cart API differs from the Cart API in that there is no need for a cart._id to manage it. All methods in the Current Cart API automatically interact with the site visitor's cart that is currently being used.

To see an estimate of the current cart's totals (including shipping costs) use the estimateCurrentCartTotals() function.

To create a checkout based on the current site visitor's cart, use the createCheckoutFromCurrentCart() function.

Before you begin

To assist in moving from the soon-to-be deprecated Stores Cart API to the eCommerce Cart API, refer to the Cart Conversion Table. Other than the cartId, cart and current cart objects are identical.

To use the Wix eCommerce Current Cart API, import { currentCart } from the wix-ecom-backend module:

Copy
import { currentCart } from "wix-ecom-backend";
Did this help?

addToCurrentCart( )


Adds catalog line items to the current site visitor's cart.

The addToCurrentCart() function returns a Promise that resolves to the updated current cart when the specified items have been added.

Note: When adding catalog items, options.lineItems.catalogReference is required.

Permissions
Manage eCommerce - all permissions
Manage Stores - all permissions
Manage Restaurants - all permissions
Learn more about app permissions.
Method Declaration
Copy
function addToCurrentCart(
  options: AddToCurrentCartOptions,
): Promise<AddToCartResponse>;
Method Parameters
optionsAddToCurrentCartOptions

Items to be added to the current cart.

Returns
Return Type:Promise<AddToCartResponse>
Add a Wix Stores product to the current cart
JavaScript
/***************************************** * Backend code - my-backend-file.web.js * ****************************************/ import { Permissions, webMethod } from "wix-web-module"; import { currentCart } from "wix-ecom-backend"; export const myAddToCurrentCartFunction = webMethod( Permissions.Anyone, async (options) => { try { const updatedCurrentCart = await currentCart.addToCurrentCart(options); console.log("Success! Updated current cart:", updatedCurrentCart); return updatedCurrentCart; } catch (error) { console.error(error); // Handle the error } }, ); /************* * Page code * ************/ import { myAddToCurrentCartFunction } from "backend/my-backend-file.web"; // Sample options object: const options = { lineItems: [ { catalogReference: { // Wix Stores appId appId: "215238eb-22a5-4c36-9e7b-e7c08025e04e", // Wix Stores productId catalogItemId: "1a2d7e83-4bef-31d5-09e1-3326ee271c09", options: { // Wix Stores variantId variantId: "132b84e8-aab8-47a1-a1f6-2c47557b64a4", }, }, quantity: 1, }, ], }; myAddToCurrentCartFunction(options) .then((updatedCurrentCart) => { const cartId = updatedCurrentCart._id; const numberOfCartLineItems = updatedCurrentCart.lineItems.length; console.log("Success! Updated cart:", updatedCurrentCart); return updatedCurrentCart; }) .catch((error) => { console.error(error); // Handle the error }); /* Promise resolves to: * * { * "_id": "e4156539-32b8-48dd-97f8-164b5a5b8740", * "lineItems": [ * { * "_id": "00000000-0000-0000-0000-000000000001", * "quantity": 1, * "catalogReference": { * "catalogItemId": "1a2d7e83-4bef-31d5-09e1-3326ee271c09", * "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e", * "options": { * "variantId": "132b84e8-aab8-47a1-a1f6-2c47557b64a4" * } * }, * "productName": { * "original": "Watch", * "translated": "Watch" * }, * "url": "https://example.wixsite.com", * "price": { * "amount": "30", * "convertedAmount": "30", * "formattedAmount": "€30.00", * "formattedConvertedAmount": "€30.00" * }, * "fullPrice": { * "amount": "30", * "convertedAmount": "30", * "formattedAmount": "€30.00", * "formattedConvertedAmount": "€30.00" * }, * "priceBeforeDiscounts": { * "amount": "30", * "convertedAmount": "30", * "formattedAmount": "€30.00", * "formattedConvertedAmount": "€30.00" * }, * "descriptionLines": [ * { * "name": { * "original": "Size", * "translated": "Size" * }, * "plainText": { * "original": "Medium", * "translated": "Medium" * }, * "lineType": "UNRECOGNISED" * }, * { * "name": { * "original": "Color", * "translated": "Color" * }, * "colorInfo": { * "original": "Grey", * "translated": "Grey", * "code": "rgb(128, 128, 128)" * }, * "lineType": "UNRECOGNISED" * } * ], * "image": "wix:image://v1/3c76e2_8891bbe3372a428aac976ac59aa0ac74~mv2.jpg#originWidth=1000&originHeight=1000", * "availability": { * "status": "AVAILABLE" * }, * "physicalProperties": { * "sku": "217537123517253", * "shippable": true * }, * "couponScopes": [ * { * "namespace": "stores", * "group": { * "name": "collection", * "entityId": "00000000-000000-000000-000000000001" * } * }, * { * "namespace": "stores", * "group": { * "name": "product", * "entityId": "1a2d7e83-4bef-31d5-09e1-3326ee271c09" * } * } * ], * "itemType": { * "preset": "PHYSICAL" * }, * "paymentOption": "FULL_PAYMENT_ONLINE" * } * ], * "buyerInfo": { * "memberId": "c43190d2-eea3-493e-b6e8-f146850c6873" * }, * "currency": "EUR", * "conversionCurrency": "EUR", * "buyerLanguage": "en", * "siteLanguage": "en", * "taxIncludedInPrices": false, * "weightUnit": "KG", * "subtotal": { * "amount": "30", * "convertedAmount": "30", * "formattedAmount": "€30.00", * "formattedConvertedAmount": "€30.00" * }, * "appliedDiscounts": [], * "inSync": false, * "_createdDate": "2022-05-23T13:17:46.801Z", * "_updatedDate": "2022-05-23T13:17:46.801Z" * } * */
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?

createCheckoutFromCurrentCart( )


Creates a checkout from the current site visitor’s cart.

The createCheckoutFromCurrentCart() function returns a Promise that resolves to the new checkout's ID when it's created.

If a checkout was already created from the current cart, that checkout will be updated with any new information from the cart.

Note: options.channelType is a required field.

Permissions
Manage eCommerce - all permissions
Manage Stores - all permissions
Manage Orders
Manage Restaurants - all permissions
Learn more about app permissions.
Method Declaration
Copy
function createCheckoutFromCurrentCart(
  options: CreateCheckoutFromCurrentCartOptions,
): Promise<CreateCheckoutResponse>;
Method Parameters
optionsCreateCheckoutFromCurrentCartOptions

Checkout creation options.

Returns
Return Type:Promise<CreateCheckoutResponse>
Create a checkout from the current cart
JavaScript
/************************************** * Backend code - my-backend-file.web.js * *************************************/ import { Permissions, webMethod } from "wix-web-module"; import { currentCart } from "wix-ecom-backend"; export const myCreateCheckoutFromCurrentCartFunction = webMethod( Permissions.Anyone, async (options) => { try { const checkoutId = await currentCart.createCheckoutFromCurrentCart(options); console.log("Success! Checkout created, checkoutId:", checkoutId); return checkoutId; } catch (error) { console.error(error); // Handle the error } }, ); /************* * Page code * ************/ import { myCreateCheckoutFromCurrentCartFunction } from "backend/my-backend-file.web"; // Sample options object: const options = { // channelType is a required field channelType: "WEB", email: "janedoe@example.com", shippingAddress: { addressLine1: "235 West 23rd Street", addressLine2: "3rd floor", city: "New York", country: "US", postalCode: "10011", streetAddress: { name: "West 23rd Street", number: "235", }, subdivision: "US-NY", }, }; myCreateCheckoutFromCurrentCartFunction(options) .then((checkoutId) => { console.log("Success! Checkout created, checkoutId:", checkoutId); return checkoutId; }) .catch((error) => { console.error(error); // Handle the error }); /* Promise resolves to: * * {"checkoutId": "a43420aa-986b-456a-a2f7-7ea5c80e9007"} * */
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?

deleteCurrentCart( )


Deletes the current site visitor's cart.

The deleteCurrentCart() function returns a Promise that resolves when the current cart is deleted.

Permissions
Manage eCommerce - all permissions
Manage Stores - all permissions
Manage Restaurants - all permissions
Learn more about app permissions.
Method Declaration
Copy
function deleteCurrentCart(): Promise<void>;
Request
This method does not take any parameters
Delete the current site visitor's cart
JavaScript
/************************************** * Backend code - my-backend-file.web.js * *************************************/ import { Permissions, webMethod } from "wix-web-module"; import { currentCart } from "wix-ecom-backend"; export const myDeleteCurrentCartFunction = webMethod( Permissions.Anyone, async () => { try { await currentCart.deleteCurrentCart(); console.log("Success! Deleted cart"); return; } catch (error) { console.error(error); // Handle the error } }, ); /************* * Page code * ************/ import { myDeleteCurrentCartFunction } from "backend/my-backend-file.web"; myDeleteCurrentCartFunction() .then(() => { console.log("Success! Deleted current cart"); return; }) .catch((error) => { console.error(error); // Handle the error });
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?

estimateCurrentCartTotals( )


Estimates the current cart's price totals (including tax), based on a selected carrier service, shipping address, and billing information.

The estimateCurrentCartTotals() function returns a Promise that resolves when the estimated totals are generated.

Note: Not passing any options properties will only estimate the cart items price totals.

Permissions
Manage eCommerce - all permissions
Read eCommerce - all read permissions
Manage Stores - all permissions
Read Stores - all read permissions
Manage Orders
Read Orders
Manage Restaurants - all permissions
Learn more about app permissions.
Method Declaration
Copy
function estimateCurrentCartTotals(
  options: EstimateCurrentCartTotalsOptions,
): Promise<EstimateTotalsResponse>;
Method Parameters
optionsEstimateCurrentCartTotalsOptions

Total estimation options.

Returns
Return Type:Promise<EstimateTotalsResponse>
Estimate the current cart's totals
JavaScript
/***************************************** * Backend code - my-backend-file.web.js * ****************************************/ import { Permissions, webMethod } from "wix-web-module"; import { currentCart } from "wix-ecom-backend"; export const myEstimateCurrentCartTotalsFunction = webMethod( Permissions.Anyone, async (estimateOptions) => { try { const estimatedCartTotals = await currentCart.estimateCurrentCartTotals(estimateOptions); console.log("Success! Cart totals estimated:", estimatedCartTotals); return estimatedCartTotals; } catch (error) { console.error(error); // Handle the error } }, ); /************* * Page code * ************/ import { myEstimateCurrentCartTotalsFunction } from "backend/my-backend-file.web"; // Sample options object: const estimateOptions = { selectedShippingOption: { code: "standard_us_shipping", }, shippingAddress: { addressLine1: "235 West 23rd Street", addressLine2: "3rd floor", city: "New York", country: "US", postalCode: "10011", streetAddress: { name: "West 23rd Street", number: "235", }, subdivision: "US-NY", }, billingAddress: { addressLine1: "235 West 23rd Street", addressLine2: "3rd floor", city: "New York", country: "US", postalCode: "10011", streetAddress: { name: "West 23rd Street", number: "235", }, subdivision: "US-NY", }, }; myEstimateCurrentCartTotalsFunction(estimateOptions) .then((estimatedCartTotals) => { const formattedShippingPrice = estimatedCartTotals.priceSummary.shipping.formattedAmount; const estimatedCartTotal = estimatedCartTotals.priceSummary.total.formattedAmount; console.log("Success! Cart totals estimated:", estimatedCartTotals); return estimatedCartTotals; }) .catch((error) => { console.error(error); // Handle the error }); /* Promise resolves to: * * { * "cart": { * "_id": "96a61a4b-6b61-47d1-a039-0213a8230ccd", * "lineItems": [ * { * "_id": "00000000-0000-0000-0000-000000000001", * "quantity": 5, * "catalogReference": { * "catalogItemId": "c8539b66-7a44-fe18-affc-afec4be8562a", * "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e" * }, * "productName": { * "original": "Shirt", * "translated": "Shirt" * }, * "url": "https://example.wixsite.com", * "price": { * "amount": "10", * "convertedAmount": "10", * "formattedAmount": "€10.00", * "formattedConvertedAmount": "€10.00" * }, * "fullPrice": { * "amount": "10", * "convertedAmount": "10", * "formattedAmount": "€10.00", * "formattedConvertedAmount": "€10.00" * }, * "priceBeforeDiscounts": { * "amount": "10", * "convertedAmount": "10", * "formattedAmount": "€10.00", * "formattedConvertedAmount": "€10.00" * }, * "descriptionLines": [], * "image": "wix:image://v1/3c76e2_c5331f937348492a97df87b0a3b34ea4~mv2.jpg#originWidth=1000&originHeight=1000", * "availability": { * "status": "AVAILABLE" * }, * "physicalProperties": { * "sku": "364115376135191", * "shippable": true * }, * "couponScopes": [ * { * "namespace": "stores", * "group": { * "name": "collection", * "entityId": "00000000-000000-000000-000000000001" * } * }, * { * "namespace": "stores", * "group": { * "name": "product", * "entityId": "c8539b66-7a44-fe18-affc-afec4be8562a" * } * } * ], * "itemType": { * "preset": "PHYSICAL" * }, * "paymentOption": "FULL_PAYMENT_ONLINE" * } * ], * "buyerInfo": { * "contactId": "f7dc17a6-825a-466e-a78e-c4abea0217db", * "memberId": "c43190d2-eea3-493e-b6e8-f146850c6873" * }, * "currency": "EUR", * "conversionCurrency": "EUR", * "buyerLanguage": "en", * "siteLanguage": "en", * "taxIncludedInPrices": false, * "weightUnit": "KG", * "subtotal": { * "amount": "50", * "convertedAmount": "50", * "formattedAmount": "€50.00", * "formattedConvertedAmount": "€50.00" * }, * "appliedDiscounts": [], * "inSync": false, * "_createdDate": "2022-05-16T12:04:01.244Z", * "_updatedDate": "2022-05-23T11:55:30.023Z" * }, * "calculatedLineItems": [ * { * "lineItemId": "00000000-0000-0000-0000-000000000001", * "pricesBreakdown": { * "totalPriceAfterTax": { * "amount": "50.00", * "convertedAmount": "50.00", * "formattedAmount": "€50.00", * "formattedConvertedAmount": "€50.00" * }, * "totalPriceBeforeTax": { * "amount": "50.00", * "convertedAmount": "50.00", * "formattedAmount": "€50.00", * "formattedConvertedAmount": "€50.00" * }, * "taxDetails": { * "taxableAmount": { * "amount": "50.00", * "convertedAmount": "50.00", * "formattedAmount": "€50.00", * "formattedConvertedAmount": "€50.00" * }, * "taxRate": "0.0", * "totalTax": { * "amount": "0.0", * "convertedAmount": "0.0", * "formattedAmount": "€0.00", * "formattedConvertedAmount": "€0.00" * }, * "rateBreakdown": [] * }, * "totalDiscount": { * "amount": "0", * "convertedAmount": "0", * "formattedAmount": "€0.00", * "formattedConvertedAmount": "€0.00" * }, * "price": { * "amount": "10.00", * "convertedAmount": "10.00", * "formattedAmount": "€10.00", * "formattedConvertedAmount": "€10.00" * }, * "priceBeforeDiscounts": { * "amount": "10.00", * "convertedAmount": "", * "formattedAmount": "", * "formattedConvertedAmount": "" * } * }, * "paymentOption": "FULL_PAYMENT_ONLINE" * } * ], * "priceSummary": { * "subtotal": { * "amount": "50.00", * "convertedAmount": "50.00", * "formattedAmount": "€50.00", * "formattedConvertedAmount": "€50.00" * }, * "shipping": { * "amount": "10.0", * "convertedAmount": "10.0", * "formattedAmount": "€10.00", * "formattedConvertedAmount": "€10.00" * }, * "tax": { * "amount": "0.0", * "convertedAmount": "0.0", * "formattedAmount": "€0.00", * "formattedConvertedAmount": "€0.00" * }, * "discount": { * "amount": "0", * "convertedAmount": "0", * "formattedAmount": "€0.00", * "formattedConvertedAmount": "€0.00" * }, * "total": { * "amount": "60.00", * "convertedAmount": "60.00", * "formattedAmount": "€60.00", * "formattedConvertedAmount": "€60.00" * } * }, * "shippingInfo": { * "region": { * "_id": "009fbe5d-89d3-7825-cbbf-1aab4d908b73", * "name": "USA shipping" * }, * "selectedCarrierServiceOption": { * "code": "ed5bbce2-9533-dff4-7db0-13702fd139c5", * "title": "Standard US Shipping", * "logistics": { * "deliveryTime": "" * }, * "cost": { * "totalPriceAfterTax": { * "amount": "10.0", * "convertedAmount": "10.0", * "formattedAmount": "€10.00", * "formattedConvertedAmount": "€10.00" * }, * "totalPriceBeforeTax": { * "amount": "10", * "convertedAmount": "10", * "formattedAmount": "€10.00", * "formattedConvertedAmount": "€10.00" * }, * "taxDetails": { * "taxRate": "0.0", * "totalTax": { * "amount": "0.0", * "convertedAmount": "0.0", * "formattedAmount": "€0.00", * "formattedConvertedAmount": "€0.00" * }, * "rateBreakdown": [] * }, * "price": { * "amount": "10", * "convertedAmount": "10", * "formattedAmount": "€10.00", * "formattedConvertedAmount": "€10.00" * } * }, * "requestedShippingOption": false, * "otherCharges": [], * "carrierId": "c8a08776-c095-4dec-8553-8f9698d86adc" * }, * "carrierServiceOptions": [ * { * "carrierId": "c8a08776-c095-4dec-8553-8f9698d86adc", * "shippingOptions": [ * { * "code": "ed5bbce2-9533-dff4-7db0-13702fd139c5", * "title": "Standard US Shipping", * "logistics": { * "deliveryTime": "" * }, * "cost": { * "price": { * "amount": "10", * "convertedAmount": "10", * "formattedAmount": "€10.00", * "formattedConvertedAmount": "€10.00" * }, * "otherCharges": [] * } * } * ] * } * ] * }, * "appliedDiscounts": [], * "calculationErrors": { * "orderValidationErrors": [] * }, * "weightUnit": "KG", * "currency": "EUR", * "payNow": { * "subtotal": { * "amount": "50.00", * "convertedAmount": "50.00", * "formattedAmount": "€50.00", * "formattedConvertedAmount": "€50.00" * }, * "shipping": { * "amount": "10.0", * "convertedAmount": "10.0", * "formattedAmount": "€10.00", * "formattedConvertedAmount": "€10.00" * }, * "tax": { * "amount": "0.0", * "convertedAmount": "0.0", * "formattedAmount": "€0.00", * "formattedConvertedAmount": "€0.00" * }, * "discount": { * "amount": "0", * "convertedAmount": "0", * "formattedAmount": "€0.00", * "formattedConvertedAmount": "€0.00" * }, * "total": { * "amount": "60.00", * "convertedAmount": "60.00", * "formattedAmount": "€60.00", * "formattedConvertedAmount": "€60.00" * } * }, * "payLater": { * "subtotal": { * "amount": "0", * "convertedAmount": "0", * "formattedAmount": "€0.00", * "formattedConvertedAmount": "€0.00" * }, * "shipping": { * "amount": "0", * "convertedAmount": "0", * "formattedAmount": "€0.00", * "formattedConvertedAmount": "€0.00" * }, * "tax": { * "amount": "0", * "convertedAmount": "0", * "formattedAmount": "€0.00", * "formattedConvertedAmount": "€0.00" * }, * "discount": { * "amount": "0", * "convertedAmount": "0", * "formattedAmount": "€0.00", * "formattedConvertedAmount": "€0.00" * }, * "total": { * "amount": "0", * "convertedAmount": "0", * "formattedAmount": "€0.00", * "formattedConvertedAmount": "€0.00" * } * }, * "membershipOptions": { * "eligibleMemberships": [], * "invalidMemberships": [], * "selectedMemberships": [] * } * } * */
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?

getCurrentCart( )


Retrieves the current site visitor's cart.

The getCurrentCart() function returns a Promise that resolves when the current cart is retrieved.

Permissions
Manage eCommerce - all permissions
Read eCommerce - all read permissions
Manage Stores - all permissions
Read Stores - all read permissions
Manage Orders
Read Orders
Manage Restaurants - all permissions
Learn more about app permissions.
Method Declaration
Copy
function getCurrentCart(): Promise<Cart>;
Request
This method does not take any parameters
Returns
Return Type:Promise<Cart>
JavaScript
/************************************** * Backend code - my-backend-file.web.js * *************************************/ import { Permissions, webMethod } from "wix-web-module"; import { currentCart } from "wix-ecom-backend"; export const myGetCurrentCartFunction = webMethod( Permissions.Anyone, async () => { try { const myCurrentCart = await currentCart.getCurrentCart(); console.log("Success! Retrieved current cart:", currentCart); return myCurrentCart; } catch (error) { console.error(error); // Handle the error } }, ); /************* * Page code * ************/ import { myGetCurrentCartFunction } from "backend/my-backend-file.web"; myGetCurrentCartFunction() .then((myCurrentCart) => { const formattedCartTotal = myCurrentCart.subtotal.formattedAmount; const numberOfCartLineItems = myCurrentCart.lineItems.length; console.log("Success! Retrieved current cart:", myCurrentCart); return myCurrentCart; }) .catch((error) => { console.error(error); // Handle the error }); /* Promise resolves to: * * { * "_id": "96a61a4b-6b61-47d1-a039-0213a8230ccd", * "lineItems": [ * { * "_id": "00000000-0000-0000-0000-000000000001", * "quantity": 3, * "catalogReference": { * "catalogItemId": "c8539b66-7a44-fe18-affc-afec4be8562a", * "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e" * }, * "productName": { * "original": "Shirt", * "translated": "Shirt" * }, * "url": "https://example.wixsite.com", * "price": { * "amount": "10", * "convertedAmount": "10", * "formattedAmount": "€10.00", * "formattedConvertedAmount": "€10.00" * }, * "fullPrice": { * "amount": "10", * "convertedAmount": "10", * "formattedAmount": "€10.00", * "formattedConvertedAmount": "€10.00" * }, * "priceBeforeDiscounts": { * "amount": "10", * "convertedAmount": "10", * "formattedAmount": "€10.00", * "formattedConvertedAmount": "€10.00" * }, * "descriptionLines": [], * "image": "wix:image://v1/3c76e2_c5331f937348492a97df87b0a3b34ea4~mv2.jpg#originWidth=1000&originHeight=1000", * "availability": { * "status": "AVAILABLE" * }, * "physicalProperties": { * "sku": "364115376135191", * "shippable": true * }, * "couponScopes": [ * { * "namespace": "stores", * "group": { * "name": "collection", * "entityId": "00000000-000000-000000-000000000001" * } * }, * { * "namespace": "stores", * "group": { * "name": "product", * "entityId": "c8539b66-7a44-fe18-affc-afec4be8562a" * } * } * ], * "itemType": { * "preset": "PHYSICAL" * }, * "paymentOption": "FULL_PAYMENT_ONLINE" * } * ], * "buyerInfo": { * "contactId": "f7dc17a6-825a-466e-a78e-c4abea0217db", * "memberId": "c43190d2-eea3-493e-b6e8-f146850c6873" * }, * "currency": "EUR", * "conversionCurrency": "EUR", * "buyerLanguage": "en", * "siteLanguage": "en", * "taxIncludedInPrices": false, * "weightUnit": "KG", * "subtotal": { * "amount": "30", * "convertedAmount": "30", * "formattedAmount": "€30.00", * "formattedConvertedAmount": "€30.00" * }, * "appliedDiscounts": [], * "inSync": false, * "_createdDate": "2022-05-16T12:04:01.244Z", * "_updatedDate": "2022-05-16T12:04:01.244Z" * } * */
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?

removeCouponFromCurrentCart( )


Removes the coupon from the current site visitor's cart.

The removeCouponFromCurrentCart() function returns a Promise that resolves to the updated current cart when the coupon is removed.

Permissions
Manage eCommerce - all permissions
Manage Stores - all permissions
Manage Restaurants - all permissions
Learn more about app permissions.
Method Declaration
Copy
function removeCouponFromCurrentCart(): Promise<RemoveCouponResponse>;
Request
This method does not take any parameters
Returns
Return Type:Promise<RemoveCouponResponse>
Remove the coupon applied to the current cart
JavaScript
/***************************************** * Backend code - my-backend-file.web.js * ****************************************/ import { Permissions, webMethod } from "wix-web-module"; import { currentCart } from "wix-ecom-backend"; export const myRemoveCouponFromCurrentCartFunction = webMethod( Permissions.Anyone, async () => { try { const updatedCurrentCart = await currentCart.removeCouponFromCurrentCart(); console.log("Success! Updated current cart:", updatedCurrentCart); return updatedCurrentCart; } catch (error) { console.error(error); // Handle the error } }, ); /************* * Page code * ************/ import { myRemoveCouponFromCurrentCartFunction } from "backend/my-backend-file.web"; myRemoveCouponFromCurrentCartFunction() .then((updatedCurrentCart) => { const cartId = updatedCurrentCart._id; const appliedDiscounts = cart.appliedDiscounts; // appliedCoupon boolean value is false if coupon was removed const appliedCoupon = appliedDiscounts.some(({ coupon }) => coupon); console.log("Success! Updated cart:", updatedCurrentCart); return updatedCurrentCart; }) .catch((error) => { console.error(error); // Handle the error }); /* Promise resolves to: * * { * "_id": "ba47a627-7bb8-4918-89b2-6a72af464765", * "appliedDiscounts": [], * "lineItems": [ * { * "_id": "00000000-0000-0000-0000-000000000001", * "quantity": 1, * "catalogReference": { * "catalogItemId": "c8539b66-7a44-fe18-affc-afec4be8562a", * "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e" * }, * "productName": { * "original": "Shirt", * "translated": "Shirt" * }, * "url": "https://example.wixsite.com", * "price": { * "amount": "10", * "convertedAmount": "10", * "formattedAmount": "€10.00", * "formattedConvertedAmount": "€10.00" * }, * "fullPrice": { * "amount": "10", * "convertedAmount": "10", * "formattedAmount": "€10.00", * "formattedConvertedAmount": "€10.00" * }, * "priceBeforeDiscounts": { * "amount": "10", * "convertedAmount": "10", * "formattedAmount": "€10.00", * "formattedConvertedAmount": "€10.00" * }, * "descriptionLines": [], * "image": "wix:image://v1/3c76e2_c5331f937348492a97df87b0a3b34ea4~mv2.jpg#originWidth=1000&originHeight=1000", * "availability": { * "status": "AVAILABLE" * }, * "physicalProperties": { * "sku": "364115376135191", * "shippable": true * }, * "couponScopes": [ * { * "namespace": "stores", * "group": { * "name": "collection", * "entityId": "00000000-000000-000000-000000000001" * } * }, * { * "namespace": "stores", * "group": { * "name": "product", * "entityId": "c8539b66-7a44-fe18-affc-afec4be8562a" * } * } * ], * "itemType": { * "preset": "PHYSICAL" * }, * "paymentOption": "FULL_PAYMENT_ONLINE" * } * ], * "buyerInfo": { * "visitorId": "4c7ce95c-9fb3-417d-9f02-b41e82b841f7" * }, * "currency": "EUR", * "conversionCurrency": "EUR", * "buyerLanguage": "en", * "siteLanguage": "en", * "taxIncludedInPrices": false, * "weightUnit": "KG", * "subtotal": { * "amount": "10", * "convertedAmount": "10", * "formattedAmount": "€10.00", * "formattedConvertedAmount": "€10.00" * }, * "inSync": true, * "_createdDate": "2022-05-15T11:31:30.484Z", * "_updatedDate": "2022-06-16T09:20:23.388Z" * } * */
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?

removeLineItemsFromCurrentCart( )


Removes line items from the current site visitor's cart.

The removeLineItemsFromCurrentCart() function returns a Promise that resolves to the updated current cart when the line items are removed.

Permissions
Manage eCommerce - all permissions
Manage Stores - all permissions
Manage Restaurants - all permissions
Learn more about app permissions.
Method Declaration
Copy
function removeLineItemsFromCurrentCart(
  lineItemIds: Array<string>,
): Promise<RemoveLineItemsResponse>;
Method Parameters
lineItemIdsArray<string>Required

IDs of the line items to remove from the cart.

Returns
Return Type:Promise<RemoveLineItemsResponse>
Remove 3 line items from the current cart
JavaScript
/************************************** * Backend code - my-backend-file.web.js * *************************************/ import { Permissions, webMethod } from "wix-web-module"; import { currentCart } from "wix-ecom-backend"; export const myRemoveLineItemsFromCurrentCartFunction = webMethod( Permissions.Anyone, async (lineItemIds) => { try { const updatedCurrentCart = await currentCart.removeLineItemsFromCurrentCart(lineItemIds); console.log("Success! Line items removed from cart:", updatedCurrentCart); return updatedCurrentCart; } catch (error) { console.error(error); // Handle the error } }, ); /************* * Page code * ************/ import { myRemoveLineItemsFromCurrentCartFunction } from "backend/my-backend-file.web"; // Sample lineItemIds array: const lineItemIds = [ "00000000-0000-0000-0000-000000000001", "00000000-0000-0000-0000-000000000002", "00000000-0000-0000-0000-000000000003", ]; myRemoveLineItemsFromCurrentCartFunction(lineItemIds) .then((updatedCurrentCart) => { const cartId = updatedCurrentCart._id; // All lineItems removed if numberOfCartItems value is 0 const numberOfCartItems = updatedCurrentCart.lineItems.length; console.log("Success! Line items removed from cart:", updatedCurrentCart); return updatedCurrentCart; }) .catch((error) => { console.error(error); // Handle the error }); /* Promise resolves to: * * { * "_id": "ba47a627-7bb8-4918-89b2-6a72af464765", * "lineItems": [], * "buyerInfo": { * "visitorId": "4c7ce95c-9fb3-417d-9f02-b41e82b841f7" * }, * "currency": "EUR", * "conversionCurrency": "EUR", * "buyerLanguage": "en", * "siteLanguage": "en", * "taxIncludedInPrices": false, * "weightUnit": "KG", * "subtotal": { * "amount": "0", * "convertedAmount": "0", * "formattedAmount": "€0.00", * "formattedConvertedAmount": "€0.00" * }, * "appliedDiscounts": [], * "inSync": true, * "_createdDate": "2022-05-15T11:31:30.484Z", * "_updatedDate": "2022-06-16T09:18:32.388Z" * } * */
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?

updateCurrentCart( )


Updates the current site visitor's cart.

The updateCurrentCart() function returns a Promise that resolves when the current cart's properties are updated.

Note: When updating catalog items, options.lineItems.catalogReference is required.

Permissions
Manage eCommerce - all permissions
Manage Stores - all permissions
Manage Restaurants - all permissions
Learn more about app permissions.
Method Declaration
Copy
function updateCurrentCart(options: UpdateCurrentCartOptions): Promise<Cart>;
Method Parameters
optionsUpdateCurrentCartOptions

Current cart update options.

Returns
Return Type:Promise<Cart>
Update the current site visitor's cart

Apply a coupon to the current cart

JavaScript
/************************************** * Backend code - my-backend-file.web.js * *************************************/ import { Permissions, webMethod } from "wix-web-module"; import { currentCart } from "wix-ecom-backend"; export const myUpdateCurrentCartFunction = webMethod( Permissions.Anyone, async (options) => { try { const updatedCurrentCart = await currentCart.updateCurrentCart(options); console.log("Success! Updated current cart:", updatedCurrentCart); return updatedCurrentCart; } catch (error) { console.error(error); // Handle the error } }, ); /************* * Page code * ************/ import { myUpdateCurrentCartFunction } from "backend/my-backend-file.web"; // Coupon code to be applied to the current cart const updateOptions = { couponCode: "SUMMERSALE10", }; myUpdateCurrentCartFunction(updateOptions) .then((updatedCurrentCart) => { const cartId = updatedCurrentCart._id; // appliedCoupon boolean resolves to true if coupon object exists const appliedCoupon = !!updatedCurrentCart.appliedDiscounts[0].coupon; console.log("Success! Updated cart:", updatedCurrentCart); return updatedCurrentCart; }) .catch((error) => { console.error(error); // Handle the error }); /* Promise resolves to: * * { * "_id": "ba47a627-7bb8-4918-89b2-6a72af464765", * "appliedDiscounts": [ * { * "coupon": { * "_id": "fbb94b06-7447-4161-9c48-59bfcdc39e77", * "code": "SUMMERSALE10" * } * } * ], * "lineItems": [ * { * "_id": "00000000-0000-0000-0000-000000000001", * "quantity": 1, * "catalogReference": { * "catalogItemId": "c8539b66-7a44-fe18-affc-afec4be8562a", * "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e" * }, * "productName": { * "original": "Shirt", * "translated": "Shirt" * }, * "url": "https://example.wixsite.com", * "price": { * "amount": "10", * "convertedAmount": "10", * "formattedAmount": "€10.00", * "formattedConvertedAmount": "€10.00" * }, * "fullPrice": { * "amount": "10", * "convertedAmount": "10", * "formattedAmount": "€10.00", * "formattedConvertedAmount": "€10.00" * }, * "priceBeforeDiscounts": { * "amount": "10", * "convertedAmount": "10", * "formattedAmount": "€10.00", * "formattedConvertedAmount": "€10.00" * }, * "descriptionLines": [], * "image": "wix:image://v1/3c76e2_c5331f937348492a97df87b0a3b34ea4~mv2.jpg#originWidth=1000&originHeight=1000", * "availability": { * "status": "AVAILABLE" * }, * "physicalProperties": { * "sku": "364115376135191", * "shippable": true * }, * "couponScopes": [ * { * "namespace": "stores", * "group": { * "name": "collection", * "entityId": "00000000-000000-000000-000000000001" * } * }, * { * "namespace": "stores", * "group": { * "name": "product", * "entityId": "c8539b66-7a44-fe18-affc-afec4be8562a" * } * } * ], * "itemType": { * "preset": "PHYSICAL" * }, * "paymentOption": "FULL_PAYMENT_ONLINE" * } * ], * "buyerInfo": { * "visitorId": "4c7ce95c-9fb3-417d-9f02-b41e82b841f7" * }, * "currency": "EUR", * "conversionCurrency": "EUR", * "buyerLanguage": "en", * "siteLanguage": "en", * "taxIncludedInPrices": false, * "weightUnit": "KG", * "subtotal": { * "amount": "10", * "convertedAmount": "10", * "formattedAmount": "€10.00", * "formattedConvertedAmount": "€10.00" * }, * "inSync": true, * "_createdDate": "2022-05-15T11:31:30.484Z", * "_updatedDate": "2022-06-16T09:20:23.388Z" * } * */
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?

updateCurrentCartLineItemQuantity( )


Updates the quantity of one or more line items in the current site visitor's cart.

The updateCurrentCartLineItemQuantity() function returns a Promise that resolves when the quantities of the current cart's line items are updated. This endpoint is only for updating the quantity of line items. To entirely remove a line item from the current cart, use removeLineItemsFromCurrentCart(). To add a new line item to the current cart, use addToCurrentCart().

This endpoint checks the amount of stock remaining for this line item. If the specified quantity is greater than the remaining stock, then the quantity returned in the response is the total amount of remaining stock.

Permissions
Manage eCommerce - all permissions
Manage Stores - all permissions
Manage Restaurants - all permissions
Learn more about app permissions.
Method Declaration
Copy
function updateCurrentCartLineItemQuantity(
  lineItems: Array<LineItemQuantityUpdate>,
): Promise<UpdateLineItemsQuantityResponse>;
Method Parameters
lineItemsArray<LineItemQuantityUpdate>Required

Line item IDs and their new quantity.

Returns
Return Type:Promise<UpdateLineItemsQuantityResponse>
Update the quantity of the current cart's line items

The first line item is updated to a quantity of 2, while the second is updated to a quantity of 3

JavaScript
/************************************** * Backend code - my-backend-file.web.js * *************************************/ import { Permissions, webMethod } from "wix-web-module"; import { currentCart } from "wix-ecom-backend"; export const myUpdateCurrentCartLineItemQuantityFunction = webMethod( Permissions.Anyone, async (lineItems) => { try { const updatedCurrentCart = await currentCart.updateCurrentCartLineItemQuantity(lineItems); console.log("Success! Line item quantities updated:", updatedCurrentCart); return updatedCurrentCart; } catch (error) { console.error(error); // Handle the error } }, ); /************* * Page code * ************/ import { myUpdateCurrentCartLineItemQuantityFunction } from "backend/my-backend-file.web"; // Sample lineItems array: const lineItems = [ { _id: "00000000-0000-0000-0000-000000000001", quantity: 2, }, { _id: "00000000-0000-0000-0000-000000000002", quantity: 3, }, ]; myUpdateCurrentCartLineItemQuantityFunction(lineItems) .then((updatedCurrentCart) => { const firstItemQuantity = updatedCurrentCart[0].quantity; const secondItemQuantity = updatedCurrentCart[1].quantity; const numberOfCartItems = updatedCurrentCart.lineItems.length; console.log("Success! Line item quantities updated:", updatedCurrentCart); return updatedCurrentCart; }) .catch((error) => { console.error(error); // Handle the error }); /* Promise resolves to: * * { * "_id": "b79fd177-ec98-4245-b9f6-f09e7afa9d04", * "lineItems": [ * { * "_id": "00000000-0000-0000-0000-000000000001", * "quantity": 2, * "catalogReference": { * "catalogItemId": "df19c1f7-07d8-a265-42f8-e8dfa824cc6e", * "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e", * "options": { * "variantId": "e62fee23-7878-437a-bf0e-292f17d11cb5" * } * }, * "productName": { * "original": "Shoe", * "translated": "Shoe" * }, * "url": "https://example.wixsite.com", * "price": { * "amount": "85", * "convertedAmount": "85", * "formattedAmount": "€85.00", * "formattedConvertedAmount": "€85.00" * }, * "fullPrice": { * "amount": "85", * "convertedAmount": "85", * "formattedAmount": "€85.00", * "formattedConvertedAmount": "€85.00" * }, * "priceBeforeDiscounts": { * "amount": "85", * "convertedAmount": "85", * "formattedAmount": "€85.00", * "formattedConvertedAmount": "€85.00" * }, * "descriptionLines": [ * { * "name": { * "original": "Color", * "translated": "Color" * }, * "colorInfo": { * "original": "Black", * "translated": "Black", * "code": "#000" * }, * "lineType": "UNRECOGNISED" * } * ], * "image": "wix:image://v1/3c76e2_bf235c38610f4d2a905db71095b351cf~mv2.jpg#originWidth=1000&originHeight=1000", * "availability": { * "status": "AVAILABLE", * "quantityAvailable": 30 * }, * "physicalProperties": { * "sku": "364215376135191", * "shippable": true * }, * "couponScopes": [ * { * "namespace": "stores", * "group": { * "name": "collection", * "entityId": "00000000-000000-000000-000000000001" * } * }, * { * "namespace": "stores", * "group": { * "name": "product", * "entityId": "df19c1f7-07d8-a265-42f8-e8dfa824cc6e" * } * } * ], * "itemType": { * "preset": "PHYSICAL" * }, * "paymentOption": "FULL_PAYMENT_ONLINE" * }, * { * "_id": "00000000-0000-0000-0000-000000000002", * "quantity": 3, * "catalogReference": { * "catalogItemId": "1a2d7e83-4bef-31d5-09e1-3326ee271c09", * "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e", * "options": { * "variantId": "132b84e8-aab8-47a1-a1f6-2c47557b64a4" * } * }, * "productName": { * "original": "Watch", * "translated": "Watch" * }, * "url": "https://example.wixsite.com", * "price": { * "amount": "30", * "convertedAmount": "30", * "formattedAmount": "€30.00", * "formattedConvertedAmount": "€30.00" * }, * "fullPrice": { * "amount": "30", * "convertedAmount": "30", * "formattedAmount": "€30.00", * "formattedConvertedAmount": "€30.00" * }, * "priceBeforeDiscounts": { * "amount": "30", * "convertedAmount": "30", * "formattedAmount": "€30.00", * "formattedConvertedAmount": "€30.00" * }, * "descriptionLines": [ * { * "name": { * "original": "Size", * "translated": "Size" * }, * "plainText": { * "original": "Medium", * "translated": "Medium" * }, * "lineType": "UNRECOGNISED" * }, * { * "name": { * "original": "Color", * "translated": "Color" * }, * "colorInfo": { * "original": "Grey", * "translated": "Grey", * "code": "rgb(128, 128, 128)" * }, * "lineType": "UNRECOGNISED" * } * ], * "image": "wix:image://v1/3c76e2_8891bbe3372a428aac976ac59aa0ac74~mv2.jpg#originWidth=1000&originHeight=1000", * "availability": { * "status": "AVAILABLE" * }, * "physicalProperties": { * "sku": "217537123517253", * "shippable": true * }, * "couponScopes": [ * { * "namespace": "stores", * "group": { * "name": "collection", * "entityId": "00000000-000000-000000-000000000001" * } * }, * { * "namespace": "stores", * "group": { * "name": "product", * "entityId": "1a2d7e83-4bef-31d5-09e1-3326ee271c09" * } * } * ], * "itemType": { * "preset": "PHYSICAL" * }, * "paymentOption": "FULL_PAYMENT_ONLINE" * } * ], * "buyerInfo": { * "visitorId": "4c7ce95c-9fb3-417d-9f02-b41e82b841f7" * }, * "currency": "EUR", * "conversionCurrency": "EUR", * "buyerLanguage": "en", * "siteLanguage": "en", * "taxIncludedInPrices": false, * "weightUnit": "KG", * "subtotal": { * "amount": "260", * "convertedAmount": "260", * "formattedAmount": "€260.00", * "formattedConvertedAmount": "€260.00" * }, * "appliedDiscounts": [], * "inSync": false, * "_createdDate": "2022-06-22T11:32:29.601Z", * "_updatedDate": "2022-06-22T11:36:48.831Z" * } * */
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?