> Portal Navigation: > > - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version. > - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages). > - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`). > - Top-level index of all portals: https://dev.wix.com/docs/llms.txt > - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt # Method name: applyCoupon(orderId: string, couponCode: string) # Method package: wixPricingPlansBackend # Method menu location: wixPricingPlansBackend --> Checkout --> applyCoupon # Method Link: https://dev.wix.com/docs/velo/apis/wix-pricing-plans-backend/checkout/apply-coupon.md # Method Description: Applies a coupon to a draft order. **Deprecated.** This function will continue to work, but will soon be deprecated. The `applyCoupon()` function returns a Promise that resolves to an order with the discounted price. A coupon can be for a percentage off the price or a fixed amount off, and it can apply to the entire duration of an order or to a specified amount of payment cycles in the order. A coupon can be created to work for all available plans or for a specific plan only. A coupon can also be limited to apply only if an order hits a minimum subtotal, or limited to the amount of uses available per coupon. Create new coupons using the [createCoupon() function](coupons/create-coupon) or [through the dashboard](https://www.wix.com/my-account/site-selector/?buttonText=Select%20Site&title=Select%20a%20Site&autoSelectOnSingleSite=true&actionUrl=https:%2F%2Fwww.wix.com%2Fdashboard%2F%7B%7BmetaSiteId%7D%7D%2Fcoupons). You can learn more about [creating coupons here](https://support.wix.com/en/article/creating-a-price-discount-coupon). Once the coupon is applied, taxes are recalculated if [taxes are configured for the site](https://support.wix.com/en/article/pricing-plans-setting-up-tax-collection). `applyCoupon()` makes a change to the order itself. To see what the price would be if the coupon is applied, but without making an actual change to the order, use the [previewOfflineOrder()](wix-pricing-plans-backend/checkout/preview-offline-order), [previewOnlineOrder()](wix-pricing-plans-backend/checkout/preview-online-order), or [previewPrice()](wix-pricing-plans-backend/checkout/preview-price) functions. When a coupon applies to the entire order, there is a single `price` for the repeating payment cycle for the entire duration of the order. **Example:** A 10% off coupon that applies to the entire order. ```javascript "prices": [{ "duration": { "cycleFrom": 1 }, "price": { "subtotal": "14.99", "coupon": { "code": "BACKTOSHAPE22", "amount": "1.5", "_id": "52f73ce1-9e31-40f7-b5d4-a621b4b4057d" }, "discount": "1.5", "total": "13.49", "currency": "USD" } }] ``` When a coupon only applies to some payment cycles of the order, there is a `price` for the period when the coupon applies and a separate `price` for the rest of the time. **Example:** A coupon that rewards the first month free. ```javascript "prices": [ { "duration": { "cycleFrom": 1, "numberOfCycles": 1 }, "price": { "subtotal": "74.99", "coupon": { "code": "ONEMONTHFREE", "amount": "74.99", "_id": "5061dd91-8cfc-4948-aae2-66fbc4b31af7" }, "discount": "74.99", "total": "0", "currency": "EUR" } }, { "duration": { "cycleFrom": 2, "numberOfCycles": 2 }, "price": { "subtotal": "74.99", "discount": "0", "total": "74.99", "currency": "EUR" } }] ``` # Method Code Examples: *** Note: do not assume any prop names or enum values other than the ones in the example. ## Apply a coupon to an online order ```javascript /********************************** * Backend code - checkout.web.js * *********************************/ import { Permissions, webMethod } from 'wix-web-module'; import { checkout } from 'wix-pricing-plans-backend'; // Sample orderId value: '18629b51-f0a3-4105-b367-c250dad96d83' // // Sample couponCode value: 'FIFTYOFF' export const myApplyCouponFunction = webMethod(Permissions.Anyone, async (orderId, couponCode) => { try { const discountedOrder = await checkout.applyCoupon(orderId, couponCode); return discountedOrder; } catch (error) { console.error(error); } }); /***************** * Frontend code * *****************/ import { checkout } from 'wix-pricing-plans-frontend'; import { myApplyCouponFunction } from 'backend/orders-checkout.web'; $w.onReady(function () { $w('#myOrderButton').onClick((event) => { const planId = "26f474d3-16a5-4891-8076-1f2f44e13021" // Create an online order in DRAFT status, and pass the order ID to the applyCoupon() function. checkout.createOnlineOrder(planId) .then((newOrder) => { const id = newOrder._id; myApplyCouponFunction(id, 'FIFTYOFF') .then((discountedOrder) => { const discountedPricing = discountedOrder.pricing; const status = discountedOrder.status; console.log(discountedPricing, status); return discountedOrder; }); }) .catch((error) => { console.error(error); }) }); }); /* Promise resolves to: * * { * "_id": "18629b51-f0a3-4105-b367-c250dad96d83", * "planId": "26f474d3-16a5-4891-8076-1f2f44e13021", * "subscriptionId": "6af934ac-0bce-4abc-ab6a-82117b90a6cc", * "wixPayOrderId": "31ba9b82-8530-4009-8d7c-c8f83c6e9d12", * "buyer": { * "memberId": "0c9bca47-1f00-4b92-af1c-7852452e949a", * "contactId": "0c9bca47-1f00-4b92-af1c-7852452e949a" * }, * "priceDetails": { * "subtotal": "25.0", * "discount": "25.0", * "total": "0", * "planPrice": "25", * "currency": "USD", * "subscription": { * "cycleDuration": { * "count": 1, * "unit": "MONTH" * }, * "cycleCount": 12 * }, * "coupon": { * "code": "FIFTYOFF", * "amount": "25.0", * "_id": "0a499915-7099-4179-a19a-4cc66044f8e3" * } * }, * "pricing": { * "subscription": { * "cycleDuration": { * "count": 1, * "unit": "MONTH" * }, * "cycleCount": 12 * }, * "prices": [ * { * "duration": { * "cycleFrom": 1, * "numberOfCycles": 2 * }, * "price": { * "subtotal": "25.0", * "coupon": { * "code": "FIFTYOFF", * "amount": "25.0", * "_id": "0a499915-7099-4179-a19a-4cc66044f8e3" * }, * "discount": "25.0", * "total": "0", * "currency": "USD" * } * }, * { * "duration": { * "cycleFrom": 3, * "numberOfCycles": 10 * }, * "price": { * "subtotal": "25", * "discount": "0", * "total": "25", * "currency": "USD" * } * } * ] * }, * "type": "ONLINE", * "orderMethod": "UNKNOWN", * "status": "DRAFT", * "autoRenewCanceled": false, * "lastPaymentStatus": "UNPAID", * "startDate": "2022-09-12T22:33:21.094Z", * "endDate": "2023-09-12T22:33:21.094Z", * "pausePeriods": [], * "earliestEndDate": "2023-09-12T22:33:21.094Z", * "currentCycle": { * "index": 1, * "startedDate": "2022-09-12T22:33:21.094Z", * "endedDate": "2022-10-12T22:33:21.094Z" * }, * "planName": "Annual plan", * "planDescription": "", * "planPrice": "25", * "_createdDate": "2022-09-12T22:33:21.094Z", * "_updatedDate": "2022-09-12T22:33:23.686Z" * } */ ``` ---