removeLineItems( )


Removes line items from the specified cart.

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

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

ID of the cart to remove line items from.


lineItemIdsArray<string>Required

IDs of the line items to remove from the cart.

Returns
Return Type:Promise<RemoveLineItemsResponse>
Remove 3 line items from a cart
JavaScript
/***************************************** * Backend code - my-backend-file.web.js * ****************************************/ import { Permissions, webMethod } from "wix-web-module"; import { cart } from "wix-ecom-backend"; export const myRemoveLineItemsFunction = webMethod( Permissions.Anyone, async (cartId, lineItemIds) => { try { const updatedCart = await cart.removeLineItems(cartId, lineItemIds); console.log("Success! Line items removed from cart:", updatedCart); return updatedCart; } catch (error) { console.error(error); // Handle the error } }, ); /************* * Page code * ************/ import { myRemoveLineItemsFunction } from "backend/my-backend-file.web"; // Sample cartId: const cartId = "ba47a627-7bb8-4918-89b2-6a72af464765"; // Sample lineItemIds array: const lineItemIds = [ "00000000-0000-0000-0000-000000000001", "00000000-0000-0000-0000-000000000002", "00000000-0000-0000-0000-000000000003", ]; myRemoveLineItemsFunction(cartId, lineItemIds) .then((updatedCart) => { const cartId = updatedCart._id; // All lineItems removed if numberOfCartItems value is 0 const numberOfCartItems = updatedCart.lineItems.length; console.log("Success! Line items removed from cart:", updatedCart); return updatedCart; }) .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?