Search.../

addCustomItemsToCart( )

Adds custom items to the cart.

Description

The addCustomItemsToCart() function returns a Promise that resolves to the current site visitor's shopping cart when the custom items have been added to the cart.

Note: When editing a site as a contributor, addCustomItemsToCart() will only work when viewing the live site.

Syntax

function addCustomItemsToCart(customItems: Array<customItem>): Promise<Cart>

addCustomItemsToCart Parameters

NAME
TYPE
DESCRIPTION
customItems

Array<customItem>

Custom items to be added to the cart.

Returns

Fulfilled - The updated cart.

Return Type:

Promise<Cart>

Was this helpful?

Add 2 custom items to the cart

Code Example

Copy Code
1import wixStores from 'wix-stores';
2
3const customItems =
4 [{
5 name: "First custom item",
6 price: 10,
7 quantity: 2,
8 note: "Note for first item"
9 },
10 {
11 name: "Second item",
12 price: 5,
13 quantity: 1,
14 note: "Note for second item"
15 }]
16
17wixStores.addCustomItemsToCart(customItems)
18 .then((updatedCart) => {
19 // Custom items added to cart
20 const cartId = updatedCart._id
21 const updatedLineItems = updatedCart.lineItems
22 })
23 .catch((error) => {
24 // Custom items not added to cart
25 console.log(error);
26 })
27
28
29/* Example of returned updatedCart object:
30 *
31 * {
32 * "_id": "5d54aa6f-f653-4bed-8c34-7f1373f88c89",
33 * "status": "INCOMPLETE",
34 * "billingAddress": {
35 * "firstName": "Jane",
36 * "lastName": "Doe",
37 * "email": "test@example.com",
38 * "phone": "+1234555890",
39 * "address": "235 W 23rd St\nNew York, New York 10011\nUnited States"
40 * },
41 * "appliedCoupon": "null",
42 * "buyerInfo": {
43 * "email": "",
44 * "firstName": "Jane",
45 * "identityType": "ADMIN",
46 * "lastName": "Doe",
47 * "phone": "+1234555890"
48 * },
49 * "buyerNote": "",
50 * "currency": {
51 * "symbol": "$",
52 * "code": "USD"
53 * },
54 * "lineItems": [
55 * {
56 * "quantity": 2,
57 * "price": 10,
58 * "name": "First custom item",
59 * "lineItemType": "CUSTOM_AMOUNT_ITEM",
60 * "customTextFields": [],
61 * "options": [],
62 * "id": 12,
63 * "mediaItem": "null",
64 * "totalPrice": 0,
65 * "weight": 0
66 * },
67 * {
68 * "quantity": 1,
69 * "price": 5,
70 * "name": "Second custom item",
71 * "lineItemType": "CUSTOM_AMOUNT_ITEM",
72 * "customTextFields": [],
73 * "options": [],
74 * "id": 13,
75 * "mediaItem": "null",
76 * "totalPrice": 0,
77 * "weight": 0
78 * }
79 * ],
80 * "shippingInfo": {
81 * "shippingAddress": {
82 * "firstName": "Jane",
83 * "lastName": "Doe",
84 * "email": "test@example.com",
85 * "phone": "+1234555890",
86 * "address": "235 W 23rd St\nNew York, New York 10011\nUnited States"
87 * }
88 * },
89 * "totals": {
90 * "discount": 0,
91 * "quantity": 3,
92 * "shipping": 0,
93 * "subtotal": 25,
94 * "tax": 0,
95 * "total": 25,
96 * "weight": 0
97 * },
98 * "weightUnit": "KG"
99 * }
100 *
101 */