Search...
removeCoupon( )
Removes the coupon from a specified cart.
Description
The removeCoupon()
function returns a Promise that resolves to the updated cart when the coupon is removed from the specified cart.
Syntax
function removeCoupon(_id: string): Promise<RemoveCouponResponse>
removeCoupon Parameters
NAME
TYPE
DESCRIPTION
_id
string
Cart ID.
Returns
Fulfilled - Updated cart.
Return Type:
Promise<
RemoveCouponResponse
>NAME
TYPE
DESCRIPTION
cart
Cart
Updated cart.
Was this helpful?
Remove coupon from a cart
Copy Code
1/**************************************2 * Backend code - my-backend-file.web.js *3 **************************************/45import { Permissions, webMethod } from 'wix-web-module';6import { cart } from 'wix-ecom-backend';78export const myRemoveCouponFunction = webMethod(Permissions.Anyone, async (cartId) => {9 try {10 const updatedCart = await cart.removeCoupon(cartId);11 console.log('Success! Updated cart:', updatedCart);12 return updatedCart;13 } catch (error) {14 console.error(error);15 // Handle the error16 }17});1819/*************20 * Page code *21 ************/2223import { myRemoveCouponFunction } from 'backend/my-backend-file.web';2425// Sample cartId:26const cartId = 'ba47a627-7bb8-4918-89b2-6a72af464765';2728myRemoveCouponFunction(cartId)29 .then((updatedCart) => {30 const cartId = updatedCart._id;31 const appliedDiscounts = cart.appliedDiscounts;32 // appliedCoupon boolean value is false if coupon was removed33 const appliedCoupon = appliedDiscounts.some(({ coupon }) => coupon);3435 console.log('Success! Updated cart:', updatedCart);36 return updatedCart;37 })38 .catch((error) => {39 console.error(error);40 // Handle the error41 });4243/* Promise resolves to:44 *45 * {46 * "_id": "ba47a627-7bb8-4918-89b2-6a72af464765",47 * "appliedDiscounts": [],48 * "lineItems": [49 * {50 * "_id": "00000000-0000-0000-0000-000000000001",51 * "quantity": 1,52 * "catalogReference": {53 * "catalogItemId": "c8539b66-7a44-fe18-affc-afec4be8562a",54 * "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e"55 * },56 * "productName": {57 * "original": "Shirt",58 * "translated": "Shirt"59 * },60 * "url": "https://example.wixsite.com",61 * "price": {62 * "amount": "10",63 * "convertedAmount": "10",64 * "formattedAmount": "€10.00",65 * "formattedConvertedAmount": "€10.00"66 * },67 * "fullPrice": {68 * "amount": "10",69 * "convertedAmount": "10",70 * "formattedAmount": "€10.00",71 * "formattedConvertedAmount": "€10.00"72 * },73 * "priceBeforeDiscounts": {74 * "amount": "10",75 * "convertedAmount": "10",76 * "formattedAmount": "€10.00",77 * "formattedConvertedAmount": "€10.00"78 * },79 * "descriptionLines": [],80 * "image": "wix:image://v1/3c76e2_c5331f937348492a97df87b0a3b34ea4~mv2.jpg#originWidth=1000&originHeight=1000",81 * "availability": {82 * "status": "AVAILABLE"83 * },84 * "physicalProperties": {85 * "sku": "364115376135191",86 * "shippable": true87 * },88 * "couponScopes": [89 * {90 * "namespace": "stores",91 * "group": {92 * "name": "collection",93 * "entityId": "00000000-000000-000000-000000000001"94 * }95 * },96 * {97 * "namespace": "stores",98 * "group": {99 * "name": "product",100 * "entityId": "c8539b66-7a44-fe18-affc-afec4be8562a"101 * }102 * }103 * ],104 * "itemType": {105 * "preset": "PHYSICAL"106 * },107 * "paymentOption": "FULL_PAYMENT_ONLINE"108 * }109 * ],110 * "buyerInfo": {111 * "visitorId": "4c7ce95c-9fb3-417d-9f02-b41e82b841f7"112 * },113 * "currency": "EUR",114 * "conversionCurrency": "EUR",115 * "buyerLanguage": "en",116 * "siteLanguage": "en",117 * "taxIncludedInPrices": false,118 * "weightUnit": "KG",119 * "subtotal": {120 * "amount": "10",121 * "convertedAmount": "10",122 * "formattedAmount": "€10.00",123 * "formattedConvertedAmount": "€10.00"124 * },125 * "inSync": true,126 * "_createdDate": "2022-05-15T11:31:30.484Z",127 * "_updatedDate": "2022-06-16T09:20:23.388Z"128 * }129 *130 */