Search.../

removeLineItems( )

Removes line items from the specified cart.

Description

The removeLineItems() function returns a Promise that resolves to the updated cart when the line items are removed from the specified cart.

Authorization

Request

This endpoint does not take any parameters

Response Object

Fulfilled - Updated cart.

NAME
TYPE
DESCRIPTION
cart
Cart

Updated cart.

Status/Error Codes

Was this helpful?

Remove 3 line items from a cart

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