Search.../

onCartCreated( )

An event that fires when a visitor adds a product to a shopping cart.

Description

The onCartCreated() event handler runs when a visitor adds an item to the shopping cart.

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

Syntax

function onCartCreated(event: CartCreatedEvent): void

onCartCreated Parameters

NAME
TYPE
DESCRIPTION
event

CartCreatedEvent

Information about the cart that was created.

Returns

This function does not return anything.

Return Type:

void

Was this helpful?

An event when a shopping cart is created

Code Example

Copy Code
1// Place this code in the events.js file
2// of your site's Backend section.
3
4export function wixStores_onCartCreated(event) {
5 let total = event.totals.total;
6}
7
8/* Full event object:
9 * {
10 * "cartId": "6d158831-1510-44ae-a420-1483a4200852",
11 * "creationTime": "2019-02-27T12:03:22.079Z",
12 * "buyerInfo": {
13 * "id": "4kf9ka09-4e9f-a02d-972f-9a5844d9d9a2",
14 * "email": "john.doe@somedomain.com",
15 * "phone": "5555555555",
16 * "firstName": "John",
17 * "lastName": "Doe"
18 * },
19 * "weightUnit": "LB",
20 * "currency": {
21 * "currency": "USD",
22 * "symbol": "$"
23 * },
24 * "totals": {
25 * "subtotal": 130,
26 * "discount": 0,
27 * "total": 130,
28 * "quantity": 1
29 * }
30 * }
31 */