Search.../

onCartCreated( )

An event that triggers when a new cart is created.

Description

The onCartCreated() event handler runs when a new cart is created. The received CartCreated object contains information about the cart that was created and event metadata.

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

Syntax

function wixEcom_onCartCreated(event: CartCreated): void

onCartCreated Parameters

NAME
TYPE
DESCRIPTION
event
Optional
CartCreated

Information about the cart that was created and event metadata.

Returns

This function does not return anything.

Return Type:

void

Was this helpful?

An event fired when a cart is created

Copy Code
1// Place this code in the events.js file
2// of your site's Backend section.
3// Add the file if it doesn't exist.
4
5export function wixEcom_onCartCreated(event) {
6 const cartSubtotal = event.entity.subtotal.amount;
7 const cartId = event.entity._id;
8 const eventId = event.metadata.id;
9 console.log('Cart created', event)
10}
11
12/* Full event object:
13 *
14 * {
15 * "metadata": {
16 * "id": "ba8e0c2e-dd90-4060-b83c-2590aa075b65",
17 * "entityId": "1c68f377-4e8f-47c1-bc72-01b18a23cb08",
18 * "eventTime": "2022-07-04T12:47:21.376865Z",
19 * "triggeredByAnonymizeRequest": false
20 * },
21 * "entity": {
22 * "_id": "1c68f377-4e8f-47c1-bc72-01b18a23cb08",
23 * "lineItems": [
24 * {
25 * "_id": "00000000-0000-0000-0000-000000000001",
26 * "quantity": 3,
27 * "catalogReference": {
28 * "catalogItemId": "df19c1f7-07d8-a265-42f8-e8dfa824cc6e",
29 * "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e",
30 * "options": {
31 * "variantId": "e62fee23-7878-437a-bf0e-292f17d11cb5"
32 * }
33 * },
34 * "productName": {
35 * "original": "Shoe",
36 * "translated": "Shoe"
37 * },
38 * "url": "https://example.wixsite.com",
39 * "price": {
40 * "amount": "85",
41 * "convertedAmount": "85",
42 * "formattedAmount": "$85.00",
43 * "formattedConvertedAmount": "$85.00"
44 * },
45 * "fullPrice": {
46 * "amount": "85",
47 * "convertedAmount": "85",
48 * "formattedAmount": "$85.00",
49 * "formattedConvertedAmount": "$85.00"
50 * },
51 * "priceBeforeDiscounts": {
52 * "amount": "85",
53 * "convertedAmount": "85",
54 * "formattedAmount": "$85.00",
55 * "formattedConvertedAmount": "$85.00"
56 * },
57 * "descriptionLines": [
58 * {
59 * "name": {
60 * "original": "Color",
61 * "translated": "Color"
62 * },
63 * "colorInfo": {
64 * "original": "Black",
65 * "translated": "Black",
66 * "code": "#000"
67 * },
68 * "lineType": "UNRECOGNISED"
69 * }
70 * ],
71 * "image": "wix:image://v1/3c76e2_bf235c38610f4d2a905db71095b351cf~mv2.jpg#originWidth=1000&originHeight=1000",
72 * "availability": {
73 * "status": "AVAILABLE",
74 * "quantityAvailable": 30
75 * },
76 * "physicalProperties": {
77 * "sku": "364215376135191",
78 * "shippable": true
79 * },
80 * "couponScopes": [
81 * {
82 * "namespace": "stores",
83 * "group": {
84 * "name": "collection",
85 * "entityId": "00000000-000000-000000-000000000001"
86 * }
87 * },
88 * {
89 * "namespace": "stores",
90 * "group": {
91 * "name": "product",
92 * "entityId": "df19c1f7-07d8-a265-42f8-e8dfa824cc6e"
93 * }
94 * }
95 * ],
96 * "itemType": {
97 * "preset": "PHYSICAL"
98 * },
99 * "paymentOption": "FULL_PAYMENT_ONLINE"
100 * }
101 * ],
102 * "buyerInfo": {
103 * "visitorId": "4c7ce95c-9fb3-417d-9f02-b41e82b841f7"
104 * },
105 * "currency": "USD",
106 * "conversionCurrency": "USD",
107 * "buyerLanguage": "en",
108 * "siteLanguage": "en",
109 * "taxIncludedInPrices": false,
110 * "weightUnit": "KG",
111 * "subtotal": {
112 * "amount": "255",
113 * "convertedAmount": "255",
114 * "formattedAmount": "$255.00",
115 * "formattedConvertedAmount": "$255.00"
116 * },
117 * "appliedDiscounts": [],
118 * "inSync": false,
119 * "_createdDate": "2022-07-04T12:47:21.371Z",
120 * "_updatedDate": "2022-07-04T12:47:21.371Z"
121 * }
122 * }
123 *
124 */