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.
function removeLineItemsFromCurrentCart(
lineItemIds: Array<string>,
): Promise<RemoveLineItemsResponse>;
IDs of the line items to remove from the cart.
/**************************************
* 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"
* }
*
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.