applyCoupon( )


Applies a coupon to a draft order.

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 or through the dashboard. You can learn more about creating coupons here.

Once the coupon is applied, taxes are recalculated if taxes are configured for the site.

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(), previewOnlineOrder(), or previewPrice() 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.

Copy

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.

Copy
Method Declaration
Copy
Method Parameters
orderIdstringRequired

ID of the order to apply coupon to.


couponCodestringRequired

Coupon code to apply.

Returns
Return Type:Promise<ApplyCoupon>
Did this help?