Search.../

removeProductFromCart( )

Removes a specified product from the cart.

Description

The removeProductFromCart() function returns a Promise that resolves to the updated shopping cart after the product is removed. Every line item in a cart has an ID. Pass this to removeProductFromCart() to remove that line item/product from the cart.

Note: removeProductFromCart() does not decrement the line item's quantity, it removes the line item/product altogether.

Syntax

function removeProductFromCart(cartLineItemId: number): Promise<Cart>

removeProductFromCart Parameters

NAME
TYPE
DESCRIPTION
cartLineItemId

number

ID of the cart line item to remove.

Returns

Fulfilled - The updated cart.

Return Type:

Promise<Cart>

Was this helpful?

Remove item with id: 3 from cart

Code Example

Copy Code
1import wixStores from 'wix-stores';
2
3const cartLineItemId = 3;
4
5wixStores.removeProductFromCart(cartLineItemId)
6 .then((updatedCart) => {
7 // Product successfully removed
8 })
9 .catch((error) => {
10 // Product not removed
11 console.error(error);
12 });
13
14/* Returned promise resolves to the updated Cart:
15*
16* {
17* "_id": "b36eb035-635a-450e-b74d-acf86ee4dfcc",
18* "appliedCoupon": {
19* "couponId": "e81e9c48-f954-4044-ba64-ccfe5c103c8f",
20* "name": "Summer Sale",
21* "code": "SummerSale",
22* "discountValue": "$10.00",
23* "couponType": "MoneyOff"
24* },
25* "billingAddress": {
26* "firstName": "John",
27* "lastName": "Doe",
28* "email":"john.doe@somedomain.com",
29* "phone":"5555555",
30* "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"
31* },
32* "buyerNote": "This is a note from the buyer.",
33* "buyerInfo":{
34* "firstName": "John",
35* "lastName": "Doe",
36* "email": "john.doe@somedomain.com",
37* "phone": "5555555555",
38* "identityType": "CONTACT"
39* },
40* "status": "INCOMPLETE",
41* "currency": {
42* "code": "USD",
43* "symbol": "$"
44* },
45* "shippingInfo": {
46* "deliveryOption": "Free Shipping",
47* "shippingAddress": {
48* "firstName": "John",
49* "lastName": "Doe",
50* "email":"john.doe@somedomain.com",
51* "phone":"5555555",
52* "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"
53* },
54* "pickupDetails":null
55* },
56* "lineItems":[
57* {
58* "quantity": 1,
59* "price": 120,
60* "name": "A product",
61* "productId": "a668ef33-f5b8-6569-d04c-1d123be68441",
62* "totalPrice": 120,
63* "lineItemType": "PHYSICAL",
64* "customTextFields": [
65* "title": "Custom Field",
66* "value": "Custom value"
67* ],
68* "mediaItem": {
69* "src": "wix:image://v1/a9ff3b_ed3b544c319b4fad9c222c791a997832.jpg/file.jpg#originWidth=1000&originHeight=1000",
70* "type": "IMAGE"
71* },
72* "sku": "21554345656",
73* "options": [ ],
74* "weight": 3,
75* "id": 1
76* },
77* {
78* "quantity": 1,
79* "price": 25,
80* "name": "Another product",
81* "productId": "1a2d7e83-4bef-31d5-09e1-3326ee271c09",
82* "totalPrice": 25,
83* "lineItemType": "PHYSICAL",
84* "mediaItem": {
85* "src": "wix:image://v1/a9ff3b_c6158b4d41784ae8b08337a331e1de7f.jpg/file.jpg#originWidth=1000&originHeight=1000",
86* "type": "IMAGE"
87* },
88* "sku": "217537123517253",
89* "options": [
90* {
91* "option": "Size",
92* "selection": "Medium"
93* },
94* {
95* "option": "Color",
96* "selection": "Black"
97* }
98* ],
99* "weight": 2,
100* "id": 2
101* }
102* ],
103* "totals": {
104* "discount": 0,
105* "quantity": 2,
106* "shipping": 0,
107* "subtotal": 145,
108* "tax": 0,
109* "total": 145,
110* "weight": 5
111* },
112* "weightUnit": "LB"
113* }
114*/
Remove item by productId

Code Example

Copy Code
1import wixStores from 'wix-stores';
2
3const productIdToRemove = "3fb6a3c8-988b-8755-04bd-5c59ae0b18ea";
4
5wixStores.getCurrentCart()
6 .then((currentCart) => {
7
8 // Find the cart item by productId
9 const itemToRemove = currentCart.lineItems.find(lineItem => lineItem.productId = productIdToRemove);
10
11 // If the item is found, remove it from the cart
12 if (itemToRemove) {
13 wixStores.removeProductFromCart(itemToRemove.id)
14 .then((updatedCart) => {
15 // Product successfully removed
16 let cartLineItems = updatedCart.lineItems;
17 })
18 .catch((error) => {
19 // Product not removed
20 console.error(error);
21 });
22 } else {
23 console.log("Item not found by productId")
24 }
25 });
26
27/* Returned promise resolves to the updated Cart:
28*
29* {
30* "_id": "b36eb035-635a-450e-b74d-acf86ee4dfcc",
31* "appliedCoupon": {
32* "couponId": "e81e9c48-f954-4044-ba64-ccfe5c103c8f",
33* "name": "Summer Sale",
34* "code": "SummerSale",
35* "discountValue": "$10.00",
36* "couponType": "MoneyOff"
37* },
38* "billingAddress": {
39* "firstName": "John",
40* "lastName": "Doe",
41* "email":"john.doe@somedomain.com",
42* "phone":"5555555",
43* "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"
44* },
45* "buyerNote": "This is a note from the buyer.",
46* "buyerInfo":{
47* "firstName": "John",
48* "lastName": "Doe",
49* "email": "john.doe@somedomain.com",
50* "phone": "5555555555",
51* "identityType": "CONTACT"
52* },
53* "status": "INCOMPLETE",
54* "currency": {
55* "code": "USD",
56* "symbol": "$"
57* },
58* "shippingInfo": {
59* "deliveryOption": "Free Shipping",
60* "shippingAddress": {
61* "firstName": "John",
62* "lastName": "Doe",
63* "email":"john.doe@somedomain.com",
64* "phone":"5555555",
65* "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"
66* },
67* "pickupDetails":null
68* },
69* "lineItems":[
70* {
71* "quantity": 1,
72* "price": 120,
73* "name": "A product",
74* "productId": "a668ef33-f5b8-6569-d04c-1d123be68441",
75* "totalPrice": 120,
76* "lineItemType": "PHYSICAL",
77* "customTextFields": [
78* "title": "Custom Field",
79* "value": "Custom value"
80* ],
81* "mediaItem": {
82* "src": "wix:image://v1/a9ff3b_ed3b544c319b4fad9c222c791a997832.jpg/file.jpg#originWidth=1000&originHeight=1000",
83* "type": "IMAGE"
84* },
85* "sku": "21554345656",
86* "options": [ ],
87* "weight": 3,
88* "id": 1
89* },
90* {
91* "quantity": 1,
92* "price": 25,
93* "name": "Another product",
94* "productId": "1a2d7e83-4bef-31d5-09e1-3326ee271c09",
95* "totalPrice": 25,
96* "lineItemType": "PHYSICAL",
97* "mediaItem": {
98* "src": "wix:image://v1/a9ff3b_c6158b4d41784ae8b08337a331e1de7f.jpg/file.jpg#originWidth=1000&originHeight=1000",
99* "type": "IMAGE"
100* },
101* "sku": "217537123517253",
102* "options": [
103* {
104* "option": "Size",
105* "selection": "Medium"
106* },
107* {
108* "option": "Color",
109* "selection": "Black"
110* }
111* ],
112* "weight": 2,
113* "id": 2
114* }
115* ],
116* "totals": {
117* "discount": 0,
118* "quantity": 2,
119* "shipping": 0,
120* "subtotal": 145,
121* "tax": 0,
122* "total": 145,
123* "weight": 5
124* },
125* "weightUnit": "LB"
126* }
127*/