Search...
removeProduct( )
Removes a specified product from the cart.
Description
The removeProduct()
function returns a Promise that resolves to the
updated cart after the product is removed.
Every line item in a cart has an ID. Pass this to removeProduct()
to remove that line item/product from the cart.
Notes:
removeProduct()
does not decrement the line item's quantity, it removes the line item/product altogether.- When editing a site as a contributor,
removeProduct()
will only work when viewing the live site.
Syntax
function removeProduct(cartLineItemId: number): Promise<CartObj>
removeProduct 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 cartCopy Code
1import { cart } from 'wix-stores-frontend';23const cartLineItemId = 3;45cart.removeProduct(cartLineItemId)6 .then((updatedCart) => {7 // Product successfully removed8 const cartLineItems = updatedCart.lineItems;9 })10 .catch((error) => {11 // Product not removed12 console.error(error);13 });141516/* Example of returned updatedCart:17 *18 * {19 * "_id": "b36eb035-635a-450e-b74d-acf86ee4dfcc",20 * "appliedCoupon": {21 * "couponId": "e81e9c48-f954-4044-ba64-ccfe5c103c8f",22 * "name": "Summer Sale",23 * "code": "SummerSale",24 * "discountValue": "$10.00",25 * "couponType": "MoneyOff"26 * },27 * "billingAddress": {28 * "firstName": "John",29 * "lastName": "Doe",30 * "email":"john.doe@somedomain.com",31 * "phone":"5555555",32 * "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"33 * },34 * "buyerNote": "This is a note from the buyer.",35 * "buyerInfo":{36 * "firstName": "John",37 * "lastName": "Doe",38 * "email": "john.doe@somedomain.com",39 * "phone": "5555555555",40 * "identityType": "CONTACT"41 * },42 * "status": "INCOMPLETE",43 * "currency": {44 * "code": "USD",45 * "symbol": "$"46 * },47 * "shippingInfo": {48 * "deliveryOption": "Free Shipping",49 * "shippingAddress": {50 * "firstName": "John",51 * "lastName": "Doe",52 * "email":"john.doe@somedomain.com",53 * "phone":"5555555",54 * "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"55 * },56 * "pickupDetails":null57 * },58 * "lineItems":[59 * {60 * "quantity": 1,61 * "price": 120,62 * "name": "A product",63 * "productId": "a668ef33-f5b8-6569-d04c-1d123be68441",64 * "totalPrice": 120,65 * "lineItemType": "PHYSICAL",66 * "customTextFields": [67 * "title": "Custom Field",68 * "value": "Custom value"69 * ],70 * "mediaItem": {71 * "src": "wix:image://v1/a9ff3b_ed3b544c319b4fad9c222c791a997832.jpg/file.jpg#originWidth=1000&originHeight=1000",72 * "type": "IMAGE"73 * },74 * "sku": "21554345656",75 * "options": [ ],76 * "weight": 3,77 * "id": 178 * },79 * {80 * "quantity": 1,81 * "price": 25,82 * "name": "Another product",83 * "productId": "1a2d7e83-4bef-31d5-09e1-3326ee271c09",84 * "totalPrice": 25,85 * "lineItemType": "PHYSICAL",86 * "mediaItem": {87 * "src": "wix:image://v1/a9ff3b_c6158b4d41784ae8b08337a331e1de7f.jpg/file.jpg#originWidth=1000&originHeight=1000",88 * "type": "IMAGE"89 * },90 * "sku": "217537123517253",91 * "options": [92 * {93 * "option": "Size",94 * "selection": "Medium"95 * },96 * {97 * "option": "Color",98 * "selection": "Black"99 * }100 * ],101 * "weight": 2,102 * "id": 2103 * }104 * ],105 * "totals": {106 * "discount": 0,107 * "quantity": 2,108 * "shipping": 0,109 * "subtotal": 145,110 * "tax": 0,111 * "total": 145,112 * "weight": 5113 * },114 * "weightUnit": "LB"115 * }116 *117 */
Remove item by
productId
Copy Code
1import { cart } from 'wix-stores-frontend';23const productIdToRemove = "3fb6a3c8-988b-8755-04bd-5c59ae0b18ea";45cart.getCurrentCart()6 .then((currentCart) => {78 // Find the cart item by productId9 const itemToRemove = currentCart.lineItems.find(lineItem => lineItem.productId === productIdToRemove);1011 // If the item is found, remove it from the cart12 if (itemToRemove) {13 cart.removeProduct(itemToRemove.id)14 .then((updatedCart) => {15 // Product successfully removed16 const cartLineItems = updatedCart.lineItems;17 })18 .catch((error) => {19 // Product not removed20 console.error(error);21 });22 } else {23 console.log("Item not found by productId")24 }25 });262728/* Example of returned updatedCart object:29 *30 * {31 * "_id": "b36eb035-635a-450e-b74d-acf86ee4dfcc",32 * "appliedCoupon": {33 * "couponId": "e81e9c48-f954-4044-ba64-ccfe5c103c8f",34 * "name": "Summer Sale",35 * "code": "SummerSale",36 * "discountValue": "$10.00",37 * "couponType": "MoneyOff"38 * },39 * "billingAddress": {40 * "firstName": "John",41 * "lastName": "Doe",42 * "email":"john.doe@somedomain.com",43 * "phone":"5555555",44 * "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"45 * },46 * "buyerNote": "This is a note from the buyer.",47 * "buyerInfo":{48 * "firstName": "John",49 * "lastName": "Doe",50 * "email": "john.doe@somedomain.com",51 * "phone": "5555555555",52 * "identityType": "CONTACT"53 * },54 * "status": "INCOMPLETE",55 * "currency": {56 * "code": "USD",57 * "symbol": "$"58 * },59 * "shippingInfo": {60 * "deliveryOption": "Free Shipping",61 * "shippingAddress": {62 * "firstName": "John",63 * "lastName": "Doe",64 * "email":"john.doe@somedomain.com",65 * "phone":"5555555",66 * "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"67 * },68 * "pickupDetails":null69 * },70 * "lineItems":[71 * {72 * "quantity": 1,73 * "price": 120,74 * "name": "A product",75 * "productId": "a668ef33-f5b8-6569-d04c-1d123be68441",76 * "totalPrice": 120,77 * "lineItemType": "PHYSICAL",78 * "customTextFields": [79 * "title": "Custom Field",80 * "value": "Custom value"81 * ],82 * "mediaItem": {83 * "src": "wix:image://v1/a9ff3b_ed3b544c319b4fad9c222c791a997832.jpg/file.jpg#originWidth=1000&originHeight=1000",84 * "type": "IMAGE"85 * },86 * "sku": "21554345656",87 * "options": [ ],88 * "weight": 3,89 * "id": 190 * },91 * {92 * "quantity": 1,93 * "price": 25,94 * "name": "Another product",95 * "productId": "1a2d7e83-4bef-31d5-09e1-3326ee271c09",96 * "totalPrice": 25,97 * "lineItemType": "PHYSICAL",98 * "mediaItem": {99 * "src": "wix:image://v1/a9ff3b_c6158b4d41784ae8b08337a331e1de7f.jpg/file.jpg#originWidth=1000&originHeight=1000",100 * "type": "IMAGE"101 * },102 * "sku": "217537123517253",103 * "options": [104 * {105 * "option": "Size",106 * "selection": "Medium"107 * },108 * {109 * "option": "Color",110 * "selection": "Black"111 * }112 * ],113 * "weight": 2,114 * "id": 2115 * }116 * ],117 * "totals": {118 * "discount": 0,119 * "quantity": 2,120 * "shipping": 0,121 * "subtotal": 145,122 * "tax": 0,123 * "total": 145,124 * "weight": 5125 * },126 * "weightUnit": "LB"127 * }128 *129 */