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