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.

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.

Method Declaration
Copy
function onNewOrder(event: NewOrderEvent): void;
Method Parameters
eventNewOrderEventRequired

The order data.

An event when a new order is placed
JavaScript
// Place this code in the events.js file // of your site's Backend section. import wixData from "wix-data"; export function wixStores_onNewOrder(event) { const newOrderId = event.orderId; const newOrderBuyerInfo = event.buyerInfo; // Get the new order's line items from the Stores/Orders collection const orderLineItems = wixData .get("Stores/Orders", newOrderId) .then((results) => { return results.lineItems; }) .catch((error) => { // Order not found in the Stores/Orders collection console.error(error); }); } /* Full event object: * * { * "orderId": "2cd413bd-ddea-4101-b122-e8b146fec05f", * "number": "10005", * "dateCreated": "2018-08-05T12:33:18.938Z", * "buyerInfo": { * "id": "6g004532-732d-829f-5kf9-f9rk42afpla04m", * "identityType": "MEMBER", * "email": "janedoe@gmail.com", * "firstName": "Jane", * "lastName": "Doe", * "phone": "5555555555" * }, * "currency": "USD", * "weightUnit": "LB", * "totals": { * "subtotal": 99.99, * "shipping": 4.99, * "tax": 8.87, * "discount": 9.99, * "total": 103.86, * "weight": 1.37, * "quantity": 2 * }, * "paymentStatus": "PAID", * "fulfillmentStatus": "FULFILLED", * "billingInfo": { * "paymentMethod": "VISA", * "externalTransactionId": "7c03ca74-eaf5-4541-8678-9b857634fdcb", * "paymentGatewayTransactionId": "29A06193U6234935D", * "paymentProviderTransactionId": "7c03ca74-eaf5-4541-8678-9b857634fdcb" * "address": { * "fullName": { * "firstName": "Jane", * "lastName": "Doe" * }, * "country": "US", * "subdivision": "US-NY", * "city": "New York", * "zipCode": "11215", * "phone": "0555555555", * "email": "janedoe@gmail.com", * "addressLine1": "525 5th Avenue" * } * }, * // The following field is only present when * // the order is a subscription * "subscriptionInfo": { * "id": "6b320feb-ddde-45be-950b-8ed277033579", * "cycleNumber": 1, * "subscriptionSettings": { * "frequency": "MONTH", * "autoRenewal": false, * "billingCycles": 3 * }, * "subscriptionOptionInfo": { * "id": "17c145c2-5d23-42c3-ac0a-e579e99c67fd", * "title": "Coffee of the month", * "description": "Monthly Coffee Sub" * } * } * } * */
Errors

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

Did this help?