Search.../

onCheckoutCreated( )

An event that triggers when a new checkout is created. For example, when a checkout is created from a cart or after using createCheckout().

Description

The onCheckoutCreated() event handler runs when a new checkout is created. The received CheckoutCreated object contains information about the checkout that was created and event metadata.

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

Syntax

function wixEcom_onCheckoutCreated(event: CheckoutCreated): void

onCheckoutCreated Parameters

NAME
TYPE
DESCRIPTION
event
Optional
CheckoutCreated

Information about the checkout that was created and event metadata.

Returns

This function does not return anything.

Return Type:

void

Was this helpful?

An event fired when a checkout 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_onCheckoutCreated(event) {
6 const checkoutSubtotal = event.entity.subtotal.amount;
7 const checkoutId = event.entity._id;
8 const eventId = event.metadata.id;
9 console.log('Checkout created', event)
10}
11
12/* Full event object:
13 *
14 * {
15 * "metadata": {
16 * "id": "10fca682-f0e5-4392-9f1e-ba26a28ec077",
17 * "entityId": "0939cbe9-72eb-47ad-bcbc-7c1ff0e0c9da",
18 * "eventTime": "2022-10-27T11:25:35.848718Z",
19 * "triggeredByAnonymizeRequest": false
20 * },
21 * "entity": {
22 * "_id": "0939cbe9-72eb-47ad-bcbc-7c1ff0e0c9da",
23 * "_createdDate": "2022-10-27T11:25:35.840Z",
24 * "_updatedDate": "2022-10-27T11:25:35.840Z",
25 * "lineItems": [
26 * {
27 * "_id": "00000000-0000-0000-0000-000000000001",
28 * "quantity": 3,
29 * "catalogReference": {
30 * "catalogItemId": "c8539b66-7a44-fe18-affc-afec4be8562a",
31 * "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e"
32 * },
33 * "productName": {
34 * "original": "Shirt",
35 * "translated": "Shirt"
36 * },
37 * "url": "https://example.wixsite.com",
38 * "price": {
39 * "amount": "10",
40 * "convertedAmount": "10",
41 * "formattedAmount": "$10.00",
42 * "formattedConvertedAmount": "$10.00"
43 * },
44 * "lineItemPrice": {
45 * "amount": "30",
46 * "convertedAmount": "30",
47 * "formattedAmount": "$30.00",
48 * "formattedConvertedAmount": "$30.00"
49 * },
50 * "fullPrice": {
51 * "amount": "10",
52 * "convertedAmount": "10",
53 * "formattedAmount": "$10.00",
54 * "formattedConvertedAmount": "$10.00"
55 * },
56 * "priceBeforeDiscounts": {
57 * "amount": "10",
58 * "convertedAmount": "10",
59 * "formattedAmount": "$10.00",
60 * "formattedConvertedAmount": "$10.00"
61 * },
62 * "totalPriceAfterTax": {
63 * "amount": "30",
64 * "convertedAmount": "30",
65 * "formattedAmount": "$30.00",
66 * "formattedConvertedAmount": "$30.00"
67 * },
68 * "totalPriceBeforeTax": {
69 * "amount": "30",
70 * "convertedAmount": "30",
71 * "formattedAmount": "$30.00",
72 * "formattedConvertedAmount": "$30.00"
73 * },
74 * "taxDetails": {
75 * "taxableAmount": {
76 * "amount": "30",
77 * "convertedAmount": "30",
78 * "formattedAmount": "$30.00",
79 * "formattedConvertedAmount": "$30.00"
80 * },
81 * "taxRate": "0",
82 * "totalTax": {
83 * "amount": "0",
84 * "convertedAmount": "0",
85 * "formattedAmount": "$0.00",
86 * "formattedConvertedAmount": "$0.00"
87 * },
88 * "rateBreakdown": []
89 * },
90 * "discount": {
91 * "amount": "0",
92 * "convertedAmount": "0",
93 * "formattedAmount": "$0.00",
94 * "formattedConvertedAmount": "$0.00"
95 * },
96 * "descriptionLines": [],
97 * "media": "wix:image://v1/3c76e2_c5331f937348492a97df87b0a3b34ea4~mv2.jpg#originWidth=1000&originHeight=1000",
98 * "availability": {
99 * "status": "AVAILABLE"
100 * },
101 * "physicalProperties": {
102 * "sku": "364115376135191",
103 * "shippable": true
104 * },
105 * "couponScopes": [
106 * {
107 * "namespace": "stores",
108 * "group": {
109 * "name": "collection",
110 * "entityId": "00000000-000000-000000-000000000001"
111 * }
112 * },
113 * {
114 * "namespace": "stores",
115 * "group": {
116 * "name": "product",
117 * "entityId": "c8539b66-7a44-fe18-affc-afec4be8562a"
118 * }
119 * }
120 * ],
121 * "itemType": {
122 * "preset": "PHYSICAL"
123 * },
124 * "paymentOption": "FULL_PAYMENT_ONLINE",
125 * "rootCatalogItemId": "c8539b66-7a44-fe18-affc-afec4be8562a"
126 * }
127 * ],
128 * "shippingInfo": {
129 * "carrierServiceOptions": []
130 * },
131 * "buyerInfo": {
132 * "memberId": "c43190d2-eea3-493e-b6e8-f146850c6873"
133 * },
134 * "conversionCurrency": "USD",
135 * "priceSummary": {
136 * "subtotal": {
137 * "amount": "30",
138 * "convertedAmount": "30",
139 * "formattedAmount": "$30.00",
140 * "formattedConvertedAmount": "$30.00"
141 * },
142 * "shipping": {
143 * "amount": "0",
144 * "convertedAmount": "0",
145 * "formattedAmount": "$0.00",
146 * "formattedConvertedAmount": "$0.00"
147 * },
148 * "tax": {
149 * "amount": "0",
150 * "convertedAmount": "0",
151 * "formattedAmount": "$0.00",
152 * "formattedConvertedAmount": "$0.00"
153 * },
154 * "discount": {
155 * "amount": "0",
156 * "convertedAmount": "0",
157 * "formattedAmount": "$0.00",
158 * "formattedConvertedAmount": "$0.00"
159 * },
160 * "total": {
161 * "amount": "30",
162 * "convertedAmount": "30",
163 * "formattedAmount": "$30.00",
164 * "formattedConvertedAmount": "$30.00"
165 * },
166 * "additionalFees": {
167 * "amount": "0",
168 * "convertedAmount": "0",
169 * "formattedAmount": "$0.00",
170 * "formattedConvertedAmount": "$0.00"
171 * }
172 * },
173 * "calculationErrors": {
174 * "orderValidationErrors": []
175 * },
176 * "appliedDiscounts": [],
177 * "customFields": [],
178 * "weightUnit": "KG",
179 * "currency": "USD",
180 * "channelType": "WEB",
181 * "siteLanguage": "en",
182 * "buyerLanguage": "en",
183 * "completed": false,
184 * "taxIncludedInPrice": false,
185 * "createdBy": {
186 * "memberId": "c43190d2-eea3-493e-b6e8-f146850c6873"
187 * },
188 * "payNow": {
189 * "subtotal": {
190 * "amount": "30",
191 * "convertedAmount": "30",
192 * "formattedAmount": "$30.00",
193 * "formattedConvertedAmount": "$30.00"
194 * },
195 * "shipping": {
196 * "amount": "0",
197 * "convertedAmount": "0",
198 * "formattedAmount": "$0.00",
199 * "formattedConvertedAmount": "$0.00"
200 * },
201 * "tax": {
202 * "amount": "0",
203 * "convertedAmount": "0",
204 * "formattedAmount": "$0.00",
205 * "formattedConvertedAmount": "$0.00"
206 * },
207 * "discount": {
208 * "amount": "0",
209 * "convertedAmount": "0",
210 * "formattedAmount": "$0.00",
211 * "formattedConvertedAmount": "$0.00"
212 * },
213 * "total": {
214 * "amount": "30",
215 * "convertedAmount": "30",
216 * "formattedAmount": "$30.00",
217 * "formattedConvertedAmount": "$30.00"
218 * },
219 * "additionalFees": {
220 * "amount": "0",
221 * "convertedAmount": "0",
222 * "formattedAmount": "$0.00",
223 * "formattedConvertedAmount": "$0.00"
224 * }
225 * },
226 * "payLater": {
227 * "subtotal": {
228 * "amount": "0",
229 * "convertedAmount": "0",
230 * "formattedAmount": "$0.00",
231 * "formattedConvertedAmount": "$0.00"
232 * },
233 * "shipping": {
234 * "amount": "0",
235 * "convertedAmount": "0",
236 * "formattedAmount": "$0.00",
237 * "formattedConvertedAmount": "$0.00"
238 * },
239 * "tax": {
240 * "amount": "0",
241 * "convertedAmount": "0",
242 * "formattedAmount": "$0.00",
243 * "formattedConvertedAmount": "$0.00"
244 * },
245 * "discount": {
246 * "amount": "0",
247 * "convertedAmount": "0",
248 * "formattedAmount": "$0.00",
249 * "formattedConvertedAmount": "$0.00"
250 * },
251 * "total": {
252 * "amount": "0",
253 * "convertedAmount": "0",
254 * "formattedAmount": "$0.00",
255 * "formattedConvertedAmount": "$0.00"
256 * },
257 * "additionalFees": {
258 * "amount": "0",
259 * "convertedAmount": "0",
260 * "formattedAmount": "$0.00",
261 * "formattedConvertedAmount": "$0.00"
262 * }
263 * },
264 * "membershipOptions": {
265 * "eligibleMemberships": [],
266 * "invalidMemberships": [],
267 * "selectedMemberships": {
268 * "memberships": []
269 * }
270 * },
271 * "additionalFees": []
272 * }
273 * }
274 *
275 */