onCartUpdated( )


An event that triggers when a cart is updated.

The onCartUpdated() event handler runs when a cart is updated. The received CartUpdated object contains information about the cart that was updated and event metadata.

Note: Backend events don't work when previewing your site.

Method Declaration
Copy
function wixEcom_onCartUpdated(event: CartUpdated): void;
Method Parameters
eventCartUpdated

Information about the cart that was updated and event metadata.

An event fired when a cart is updated
JavaScript
// Place this code in the events.js file // of your site's Backend section. // Add the file if it doesn't exist. export function wixEcom_onCartUpdated(event) { const cartSubtotal = event.entity.subtotal.amount; const cartId = event.entity._id; const eventId = event.metadata.id; console.log("Cart updated", event); } /* Full event object: * * { * "metadata": { * "id": "e508b5f9-a7d2-4b37-94ce-2b7767cfa49c", * "entityId": "b79fd177-ec98-4245-b9f6-f09e7afa9d04", * "eventTime": "2022-10-27T11:42:17.211724Z", * "triggeredByAnonymizeRequest": false * }, * "entity": { * "_id": "b79fd177-ec98-4245-b9f6-f09e7afa9d04", * "lineItems": [ * { * "_id": "00000000-0000-0000-0000-000000000001", * "quantity": 2, * "catalogReference": { * "catalogItemId": "df19c1f7-07d8-a265-42f8-e8dfa824cc6e", * "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e", * "options": { * "variantId": "e62fee23-7878-437a-bf0e-292f17d11cb5" * } * }, * "productName": { * "original": "Shoe", * "translated": "Shoe" * }, * "url": "https://example.wixsite.com", * "price": { * "amount": "85", * "convertedAmount": "85", * "formattedAmount": "$85.00", * "formattedConvertedAmount": "$85.00" * }, * "fullPrice": { * "amount": "85", * "convertedAmount": "85", * "formattedAmount": "$85.00", * "formattedConvertedAmount": "$85.00" * }, * "priceBeforeDiscounts": { * "amount": "85", * "convertedAmount": "85", * "formattedAmount": "$85.00", * "formattedConvertedAmount": "$85.00" * }, * "descriptionLines": [ * { * "name": { * "original": "Color", * "translated": "Color" * }, * "colorInfo": { * "original": "Black", * "translated": "Black", * "code": "#000" * }, * "lineType": "UNRECOGNISED" * } * ], * "image": "wix:image://v1/3c76e2_bf235c38610f4d2a905db71095b351cf~mv2.jpg#originWidth=1000&originHeight=1000", * "availability": { * "status": "AVAILABLE", * "quantityAvailable": 30 * }, * "physicalProperties": { * "sku": "364215376135191", * "shippable": true * }, * "couponScopes": [ * { * "namespace": "stores", * "group": { * "name": "collection", * "entityId": "00000000-000000-000000-000000000001" * } * }, * { * "namespace": "stores", * "group": { * "name": "product", * "entityId": "df19c1f7-07d8-a265-42f8-e8dfa824cc6e" * } * } * ], * "itemType": { * "preset": "PHYSICAL" * }, * "paymentOption": "FULL_PAYMENT_ONLINE" * }, * { * "_id": "00000000-0000-0000-0000-000000000002", * "quantity": 3, * "catalogReference": { * "catalogItemId": "1a2d7e83-4bef-31d5-09e1-3326ee271c09", * "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e", * "options": { * "variantId": "132b84e8-aab8-47a1-a1f6-2c47557b64a4" * } * }, * "productName": { * "original": "Watch", * "translated": "Watch" * }, * "url": "https://example.wixsite.com", * "price": { * "amount": "30", * "convertedAmount": "30", * "formattedAmount": "$30.00", * "formattedConvertedAmount": "$30.00" * }, * "fullPrice": { * "amount": "30", * "convertedAmount": "30", * "formattedAmount": "$30.00", * "formattedConvertedAmount": "$30.00" * }, * "priceBeforeDiscounts": { * "amount": "30", * "convertedAmount": "30", * "formattedAmount": "$30.00", * "formattedConvertedAmount": "$30.00" * }, * "descriptionLines": [ * { * "name": { * "original": "Size", * "translated": "Size" * }, * "plainText": { * "original": "Medium", * "translated": "Medium" * }, * "lineType": "UNRECOGNISED" * }, * { * "name": { * "original": "Color", * "translated": "Color" * }, * "colorInfo": { * "original": "Grey", * "translated": "Grey", * "code": "rgb(128, 128, 128)" * }, * "lineType": "UNRECOGNISED" * } * ], * "image": "wix:image://v1/3c76e2_8891bbe3372a428aac976ac59aa0ac74~mv2.jpg#originWidth=1000&originHeight=1000", * "availability": { * "status": "AVAILABLE" * }, * "physicalProperties": { * "sku": "217537123517253", * "shippable": true * }, * "couponScopes": [ * { * "namespace": "stores", * "group": { * "name": "collection", * "entityId": "00000000-000000-000000-000000000001" * } * }, * { * "namespace": "stores", * "group": { * "name": "product", * "entityId": "1a2d7e83-4bef-31d5-09e1-3326ee271c09" * } * } * ], * "itemType": { * "preset": "PHYSICAL" * }, * "paymentOption": "FULL_PAYMENT_ONLINE" * } * ], * "buyerInfo": { * "visitorId": "4c7ce95c-9fb3-417d-9f02-b41e82b841f7" * }, * "currency": "USD", * "conversionCurrency": "USD", * "buyerLanguage": "en", * "siteLanguage": "en", * "taxIncludedInPrices": false, * "weightUnit": "KG", * "subtotal": { * "amount": "260", * "convertedAmount": "260", * "formattedAmount": "$260.00", * "formattedConvertedAmount": "$260.00" * }, * "appliedDiscounts": [], * "inSync": false, * "_createdDate": "2022-06-22T11:32:29.601Z", * "_updatedDate": "2022-07-03T13:19:26.450Z" * }, * "metadata": { * "id": "cac6f823-0ec7-4dd0-9147-48738c76134c", * "entityId": "b79fd177-ec98-4245-b9f6-f09e7afa9d04", * "eventTime": "2022-07-03T13:19:26.458843Z", * "triggeredByAnonymizeRequest": false * } * } * */
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?