onCartCreated( )
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.
Description
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.
Syntax
function onCartCreated(event: CartCreatedEvent): void
onCartCreated Parameters
NAME
TYPE
DESCRIPTION
Information about the cart that was created.
Returns
This function does not return anything.
Return Type:
Was this helpful?
An event when a shopping cart is created
1// Place this code in the events.js file2// of your site's Backend section.34export function wixStores_onCartCreated(event) {5 let total = event.totals.total;6}78/* Full event object:9 *10 * {11 * "cartId": "6d158831-1510-44ae-a420-1483a4200852",12 * "creationTime": "2019-02-27T12:03:22.079Z",13 * "buyerInfo": {14 * "id": "4kf9ka09-4e9f-a02d-972f-9a5844d9d9a2",15 * "email": "john.doe@somedomain.com",16 * "phone": "5555555555",17 * "firstName": "John",18 * "lastName": "Doe"19 * },20 * "weightUnit": "LB",21 * "currency": {22 * "currency": "USD",23 * "symbol": "$"24 * },25 * "totals": {26 * "subtotal": 130,27 * "discount": 0,28 * "total": 130,29 * "quantity": 130 * }31 * }32 *33 */