Search.../

onNewOrder( )

Deprecated. This event will continue to work until September 4, 2024, but a newer version is available at wix-ecom-backend.Events.onOrderApproved().

We recommend you migrate to the new Wix eCommerce APIs as soon as possible.

Description

An event that fires when a new order is placed.

The onNewOrder() event handler runs when a new order is placed in your site's store. The received NewOrderEvent object contains information about the new order that was placed.

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

Syntax

function onNewOrder(event: NewOrderEvent): void

onNewOrder Parameters

NAME
TYPE
DESCRIPTION
event
NewOrderEvent

The order data.

Returns

This function does not return anything.

Return Type:

void

Was this helpful?

An event when a new order is placed

Copy Code
1// Place this code in the events.js file
2// of your site's Backend section.
3
4import wixData from 'wix-data';
5
6export function wixStores_onNewOrder(event) {
7 const newOrderId = event.orderId;
8 const newOrderBuyerInfo = event.buyerInfo;
9
10 // Get the new order's line items from the Stores/Orders collection
11 const orderLineItems = wixData.get("Stores/Orders", newOrderId)
12 .then((results) => {
13 return results.lineItems
14 })
15 .catch((error) => {
16 // Order not found in the Stores/Orders collection
17 console.error(error);
18 });
19}
20
21/* Full event object:
22 *
23 * {
24 * "orderId": "2cd413bd-ddea-4101-b122-e8b146fec05f",
25 * "number": "10005",
26 * "dateCreated": "2018-08-05T12:33:18.938Z",
27 * "buyerInfo": {
28 * "id": "6g004532-732d-829f-5kf9-f9rk42afpla04m",
29 * "identityType": "MEMBER",
30 * "email": "janedoe@gmail.com",
31 * "firstName": "Jane",
32 * "lastName": "Doe",
33 * "phone": "5555555555"
34 * },
35 * "currency": "USD",
36 * "weightUnit": "LB",
37 * "totals": {
38 * "subtotal": 99.99,
39 * "shipping": 4.99,
40 * "tax": 8.87,
41 * "discount": 9.99,
42 * "total": 103.86,
43 * "weight": 1.37,
44 * "quantity": 2
45 * },
46 * "paymentStatus": "PAID",
47 * "fulfillmentStatus": "FULFILLED",
48 * "billingInfo": {
49 * "paymentMethod": "VISA",
50 * "externalTransactionId": "7c03ca74-eaf5-4541-8678-9b857634fdcb",
51 * "paymentGatewayTransactionId": "29A06193U6234935D",
52 * "paymentProviderTransactionId": "7c03ca74-eaf5-4541-8678-9b857634fdcb"
53 * "address": {
54 * "fullName": {
55 * "firstName": "Jane",
56 * "lastName": "Doe"
57 * },
58 * "country": "US",
59 * "subdivision": "US-NY",
60 * "city": "New York",
61 * "zipCode": "11215",
62 * "phone": "0555555555",
63 * "email": "janedoe@gmail.com",
64 * "addressLine1": "525 5th Avenue"
65 * }
66 * },
67 * // The following field is only present when
68 * // the order is a subscription
69 * "subscriptionInfo": {
70 * "id": "6b320feb-ddde-45be-950b-8ed277033579",
71 * "cycleNumber": 1,
72 * "subscriptionSettings": {
73 * "frequency": "MONTH",
74 * "autoRenewal": false,
75 * "billingCycles": 3
76 * },
77 * "subscriptionOptionInfo": {
78 * "id": "17c145c2-5d23-42c3-ac0a-e579e99c67fd",
79 * "title": "Coffee of the month",
80 * "description": "Monthly Coffee Sub"
81 * }
82 * }
83 * }
84 *
85 */