Search.../

removeLineItemsFromCurrentCart( )

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

Description

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

Syntax

function removeLineItemsFromCurrentCart(lineItemIds: Array<string>): Promise<RemoveLineItemsResponse>

removeLineItemsFromCurrentCart Parameters

NAME
TYPE
DESCRIPTION
lineItemIds
Array<
string
>

IDs of the line items to remove from the cart.

Returns

Return Type:

Promise<
RemoveLineItemsResponse
>
NAME
TYPE
DESCRIPTION
cart
Cart

Updated cart.

Was this helpful?

Remove 3 line items from the current cart

Copy Code
1/**************************************
2 * Backend code - my-backend-file.web.js *
3 *************************************/
4
5import { Permissions, webMethod } from 'wix-web-module';
6import { currentCart } from 'wix-ecom-backend';
7
8export const myRemoveLineItemsFromCurrentCartFunction = webMethod(Permissions.Anyone, async (lineItemIds) => {
9 try {
10 const updatedCurrentCart = await currentCart.removeLineItemsFromCurrentCart(lineItemIds);
11 console.log('Success! Line items removed from cart:', updatedCurrentCart);
12 return updatedCurrentCart;
13 } catch (error) {
14 console.error(error);
15 // Handle the error
16 }
17});
18
19/*************
20 * Page code *
21 ************/
22
23import { myRemoveLineItemsFromCurrentCartFunction } from 'backend/my-backend-file.web';
24
25// Sample lineItemIds array:
26const lineItemIds = [
27 '00000000-0000-0000-0000-000000000001',
28 '00000000-0000-0000-0000-000000000002',
29 '00000000-0000-0000-0000-000000000003'
30]
31
32myRemoveLineItemsFromCurrentCartFunction(lineItemIds)
33 .then((updatedCurrentCart) => {
34 const cartId = updatedCurrentCart._id;
35 // All lineItems removed if numberOfCartItems value is 0
36 const numberOfCartItems = updatedCurrentCart.lineItems.length;
37
38 console.log('Success! Line items removed from cart:', updatedCurrentCart);
39 return updatedCurrentCart;
40 })
41 .catch((error) => {
42 console.error(error);
43 // Handle the error
44 });
45
46/* Promise resolves to:
47 *
48 * {
49 * "_id": "ba47a627-7bb8-4918-89b2-6a72af464765",
50 * "lineItems": [],
51 * "buyerInfo": {
52 * "visitorId": "4c7ce95c-9fb3-417d-9f02-b41e82b841f7"
53 * },
54 * "currency": "EUR",
55 * "conversionCurrency": "EUR",
56 * "buyerLanguage": "en",
57 * "siteLanguage": "en",
58 * "taxIncludedInPrices": false,
59 * "weightUnit": "KG",
60 * "subtotal": {
61 * "amount": "0",
62 * "convertedAmount": "0",
63 * "formattedAmount": "€0.00",
64 * "formattedConvertedAmount": "€0.00"
65 * },
66 * "appliedDiscounts": [],
67 * "inSync": true,
68 * "_createdDate": "2022-05-15T11:31:30.484Z",
69 * "_updatedDate": "2022-06-16T09:18:32.388Z"
70 * }
71 *
72 */