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