Deprecated.
This event will continue to work until September 4, 2024, but a newer version is available at
wix-ecom-backend.Events.onCartCreated()
.
We recommend you migrate to the new Wix eCommerce APIs as soon as possible.
For more info about the differences between the Stores Cart and eCommerce Cart, refer to the cart conversion table.
An event that fires when a cart is created.
The onCartCreated()
event handler runs the first time a site visitor adds a product to their shopping cart.
Removing all items from the cart and adding a new item does not create a new cart and does not trigger this event.
Note: Backend events don't work when previewing your site.
function onCartCreated(event: CartCreatedEvent): void;
Information about the cart that was created.
// Place this code in the events.js file
// of your site's Backend section.
export function wixStores_onCartCreated(event) {
let total = event.totals.total;
}
/* Full event object:
*
* {
* "cartId": "6d158831-1510-44ae-a420-1483a4200852",
* "creationTime": "2019-02-27T12:03:22.079Z",
* "buyerInfo": {
* "id": "4kf9ka09-4e9f-a02d-972f-9a5844d9d9a2",
* "email": "john.doe@somedomain.com",
* "phone": "5555555555",
* "firstName": "John",
* "lastName": "Doe"
* },
* "weightUnit": "LB",
* "currency": {
* "currency": "USD",
* "symbol": "$"
* },
* "totals": {
* "subtotal": 130,
* "discount": 0,
* "total": 130,
* "quantity": 1
* }
* }
*
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.