Search.../

removeCouponFromCurrentCart( )

Removes the coupon from the current site visitor's cart.

Description

The removeCouponFromCurrentCart() function returns a Promise that resolves to the updated current cart when the coupon is removed.

Syntax

function removeCouponFromCurrentCart(): Promise<RemoveCouponResponse>

removeCouponFromCurrentCart Parameters

This function does not take any parameters.

Returns

Fulfilled - Updated current cart.

Return Type:

Promise<
RemoveCouponResponse
>
NAME
TYPE
DESCRIPTION
cart
Cart

Updated cart.

Was this helpful?

Remove the coupon applied to the current cart

Copy Code
1/**************************************
2 * Backend code - my-backend-file.jsw *
3 *************************************/
4
5import { currentCart } from 'wix-ecom-backend';
6
7export async function myRemoveCouponFromCurrentCartFunction() {
8 try {
9 const updatedCurrentCart = await currentCart.removeCouponFromCurrentCart();
10 console.log('Success! Updated current cart:', updatedCurrentCart);
11 return updatedCurrentCart;
12 } catch (error) {
13 console.error(error);
14 // Handle the error
15 }
16}
17
18/*************
19 * Page code *
20 ************/
21
22import { myRemoveCouponFromCurrentCartFunction } from 'backend/my-backend-file';
23
24myRemoveCouponFromCurrentCartFunction()
25 .then((updatedCurrentCart) => {
26 const cartId = updatedCurrentCart._id;
27 const appliedDiscounts = cart.appliedDiscounts;
28 // appliedCoupon boolean value is false if coupon was removed
29 const appliedCoupon = appliedDiscounts.some(({coupon}) => coupon);
30
31 console.log('Success! Updated cart:', updatedCurrentCart);
32 return updatedCurrentCart;
33 })
34 .catch((error) => {
35 console.error(error);
36 // Handle the error
37 });
38
39/* Promise resolves to:
40 *
41 * {
42 * "_id": "ba47a627-7bb8-4918-89b2-6a72af464765",
43 * "appliedDiscounts": [],
44 * "lineItems": [
45 * {
46 * "_id": "00000000-0000-0000-0000-000000000001",
47 * "quantity": 1,
48 * "catalogReference": {
49 * "catalogItemId": "c8539b66-7a44-fe18-affc-afec4be8562a",
50 * "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e"
51 * },
52 * "productName": {
53 * "original": "Shirt",
54 * "translated": "Shirt"
55 * },
56 * "url": "https://example.wixsite.com",
57 * "price": {
58 * "amount": "10",
59 * "convertedAmount": "10",
60 * "formattedAmount": "€10.00",
61 * "formattedConvertedAmount": "€10.00"
62 * },
63 * "fullPrice": {
64 * "amount": "10",
65 * "convertedAmount": "10",
66 * "formattedAmount": "€10.00",
67 * "formattedConvertedAmount": "€10.00"
68 * },
69 * "priceBeforeDiscounts": {
70 * "amount": "10",
71 * "convertedAmount": "10",
72 * "formattedAmount": "€10.00",
73 * "formattedConvertedAmount": "€10.00"
74 * },
75 * "descriptionLines": [],
76 * "image": "wix:image://v1/3c76e2_c5331f937348492a97df87b0a3b34ea4~mv2.jpg#originWidth=1000&originHeight=1000",
77 * "availability": {
78 * "status": "AVAILABLE"
79 * },
80 * "physicalProperties": {
81 * "sku": "364115376135191",
82 * "shippable": true
83 * },
84 * "couponScopes": [
85 * {
86 * "namespace": "stores",
87 * "group": {
88 * "name": "collection",
89 * "entityId": "00000000-000000-000000-000000000001"
90 * }
91 * },
92 * {
93 * "namespace": "stores",
94 * "group": {
95 * "name": "product",
96 * "entityId": "c8539b66-7a44-fe18-affc-afec4be8562a"
97 * }
98 * }
99 * ],
100 * "itemType": {
101 * "preset": "PHYSICAL"
102 * },
103 * "paymentOption": "FULL_PAYMENT_ONLINE"
104 * }
105 * ],
106 * "buyerInfo": {
107 * "visitorId": "4c7ce95c-9fb3-417d-9f02-b41e82b841f7"
108 * },
109 * "currency": "EUR",
110 * "conversionCurrency": "EUR",
111 * "buyerLanguage": "en",
112 * "siteLanguage": "en",
113 * "taxIncludedInPrices": false,
114 * "weightUnit": "KG",
115 * "subtotal": {
116 * "amount": "10",
117 * "convertedAmount": "10",
118 * "formattedAmount": "€10.00",
119 * "formattedConvertedAmount": "€10.00"
120 * },
121 * "inSync": true,
122 * "_createdDate": "2022-05-15T11:31:30.484Z",
123 * "_updatedDate": "2022-06-16T09:20:23.388Z"
124 * }
125 *
126 */
127