Search.../

removeProductFromCart( )

Deprecated. This function will continue to work, but a newer version is available at wix-stores.cart.removeProduct().

Description

The removeProductFromCart() function returns a Promise that resolves to the updated cart after the product is removed.

Migration Instructions

If this function is already in your code, it will continue to work. To stay compatible with future changes, migrate to wix-stores.cart.removeProduct().

To migrate to the new function:

  1. Add the new import statement:

    import { cart } from 'wix-stores'
    javascript | Copy Code
  2. If you plan to migrate all functions that use wix-stores, remove the original import wixStores statement.

  3. Look for any code that uses wixStores.removeProductFromCart(), and replace it with cart.removeProduct(). Update your code to work with the new cart.removeProduct() call and response properties.

  4. Test your changes to make sure your code behaves as expected.

Syntax

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

removeProductFromCart Parameters

NAME
TYPE
DESCRIPTION
cartLineItemId
number

ID of the cart line item to remove.

Returns

Fulfilled - The updated cart.

Return Type:

Promise<CartObj>
NAME
TYPE
DESCRIPTION
_id
string

Unique identifier of the shopping cart.

appliedCoupon
CartAppliedCoupon

Coupon applied in the shopping cart.

billingAddress
CartAddress

Cart billing address.

buyerInfo
CartBuyerInfo

The buyer's information.

status
string

Cart status. Either "INCOMPLETE" or "COMPLETE".

currency
Currency

Currency of the shopping cart.

shippingInfo
CartShippingInfo

The shopping cart's shipping information.

lineItems
Array<CartLineItem>

Items in the shopping cart.

totals
OrderTotals

The shopping cart's totals.

weightUnit
string

The order's units of weight. One of: "KG", "LB", or "UNSPECIFIED_WEIGHT_UNIT".

Was this helpful?

Remove item with id: 3 from cart

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

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