Search.../

applyCoupon( )

Adds and applies a coupon to the cart.

Description

The applyCoupon() function returns a Promise that resolves to the current site visitor's cart when the specified coupon has been applied.

The cart can only hold one coupon. If a coupon is already applied to the cart, passing a different couponCode to applyCoupon() will replace the existing one.

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

Authorization

Request

This endpoint does not take any parameters

Response Object

Fulfilled - The updated cart.

NAME
TYPE
DESCRIPTION
_id
string

Unique identifier of the shopping cart.

appliedCoupon
CartAppliedCoupon

Coupon applied in the shopping cart.

billingAddress
CartAddress

Cart billing address.

buyerInfo
CartBuyerInfo

The buyer's information.

status
string

Cart status. Either "INCOMPLETE" or "COMPLETE".

currency
Currency

Currency of the shopping cart.

shippingInfo
CartShippingInfo

The shopping cart's shipping information.

lineItems
Array<CartLineItem>

Items in the shopping cart.

totals
OrderTotals

The shopping cart's totals.

weightUnit
string

The order's units of weight. One of: "KG", "LB", or "UNSPECIFIED_WEIGHT_UNIT".

Status/Error Codes

Was this helpful?

Apply coupon code "SummerSale" to the cart

Copy Code
1import { cart } from 'wix-stores-frontend';
2
3const couponCode = "SummerSale";
4
5cart.applyCoupon(couponCode)
6 .then((updatedCart) => {
7 const couponDiscount = updatedCart.appliedCoupon.discountValue;
8 })
9 .catch((error) => {
10 console.error(error);
11 });
12
13/* Example of returned updatedCart object:
14*
15* {
16* "_id": "b36eb035-635a-450e-b74d-acf86ee4dfcc",
17* "appliedCoupon": {
18* "couponId": "e81e9c48-f954-4044-ba64-ccfe5c103c8f",
19* "name": "Summer Sale",
20* "code": "SummerSale",
21* "discountValue": "$10.00",
22* "couponType": "MoneyOff"
23* },
24* "billingAddress": {
25* "firstName": "John",
26* "lastName": "Doe",
27* "email":"john.doe@somedomain.com",
28* "phone":"5555555",
29* "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"
30* },
31* "buyerNote": "This is a note from the buyer.",
32* "buyerInfo":{
33* "firstName": "John",
34* "lastName": "Doe",
35* "email": "john.doe@somedomain.com",
36* "phone": "5555555555",
37* "identityType": "CONTACT"
38* },
39* "status": "INCOMPLETE",
40* "currency": {
41* "code": "USD",
42* "symbol": "$"
43* },
44* "shippingInfo": {
45* "deliveryOption": "Free Shipping",
46* "shippingAddress": {
47* "firstName": "John",
48* "lastName": "Doe",
49* "email":"john.doe@somedomain.com",
50* "phone":"5555555",
51* "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"
52* },
53* "pickupDetails":null
54* },
55* "lineItems":[
56* {
57* "quantity": 1,
58* "price": 120,
59* "name": "A product",
60* "productId": "a668ef33-f5b8-6569-d04c-1d123be68441",
61* "totalPrice": 120,
62* "lineItemType": "PHYSICAL",
63* "customTextFields": [
64* "title": "Custom Field",
65* "value": "Custom value"
66* ],
67* "mediaItem": {
68* "src": "wix:image://v1/a9ff3b_ed3b544c319b4fad9c222c791a997832.jpg/file.jpg#originWidth=1000&originHeight=1000",
69* "type": "IMAGE"
70* },
71* "sku": "21554345656",
72* "options": [ ],
73* "weight": 3,
74* "id": 1
75* },
76* {
77* "quantity": 1,
78* "price": 25,
79* "name": "Another product",
80* "productId": "1a2d7e83-4bef-31d5-09e1-3326ee271c09",
81* "totalPrice": 25,
82* "lineItemType": "PHYSICAL",
83* "mediaItem": {
84* "src": "wix:image://v1/a9ff3b_c6158b4d41784ae8b08337a331e1de7f.jpg/file.jpg#originWidth=1000&originHeight=1000",
85* "type": "IMAGE"
86* },
87* "sku": "217537123517253",
88* "options": [
89* {
90* "option": "Size",
91* "selection": "Medium"
92* },
93* {
94* "option": "Color",
95* "selection": "Black"
96* }
97* ],
98* "weight": 2,
99* "id": 2
100* }
101* ],
102* "totals": {
103* "discount": 10,
104* "quantity": 2,
105* "shipping": 0,
106* "subtotal": 145,
107* "tax": 0,
108* "total": 135,
109* "weight": 5
110* },
111* "weightUnit": "LB"
112* }
113*/