previewPrice( )


Provides a preview of an order's pricing as if was purchased.

The previewPrice() function returns a Promise that resolves to a temporary preview of the order's price.

The price preview uses the same logic for calculating prices as used when purchasing a plan, but the preview is not saved. If taxes are configured for the site, taxes are applied to the preview. If not, the tax previews as null.

Buyers do not have to be logged in to preview the price, as such, the details returned by this function are not buyer-specific. To generate a preview of a purchase for a specific buyer, use the previewOfflineOrder() or previewOnlineOrder() functions.

Method Declaration
Copy
function previewPrice(
  planId: string,
  couponCode: string,
): Promise<PricePreview>;
Method Parameters
planIdstringRequired

ID of the plan whose pricing should be previewed.


couponCodestring

Coupon code to apply.

To learn more about coupons, see applyCoupon().

Returns
Return Type:Promise<PricePreview>
Preview the pricing details for a plan to be purchased with a 10%-off coupon
JavaScript
import { Permissions, webMethod } from "wix-web-module"; import { checkout } from "wix-pricing-plans-backend"; // Sample planId value: '6d7537c5-beac-44a3-bea3-b947ddc56b31' // // Sample couponCode value: 'BACKTOSHAPE22' export const myPreviewPriceFunction = webMethod( Permissions.Anyone, async (planId, couponCode) => { try { const pricePreview = await checkout.previewPrice(planId, couponCode); const orderPricing = pricePreview.prices.price.total; const currency = pricePreview.prices.price.currency; return pricePreview; } catch (error) { console.error(error); } }, ); /* Promise resolves to: * * { * "price": { * "subtotal": "14.99", * "discount": "1.5", * "total": "13.49", * "planPrice": "14.99", * "currency": "USD", * "subscription": { * "cycleDuration": { * "count": 1, * "unit": "MONTH" * }, * "cycleCount": 0 * }, * "coupon": { * "code": "BACKTOSHAPE22", * "amount": "1.5", * "_id": "52f73ce1-9e31-40f7-b5d4-a621b4b4057d" * } * }, * "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" * } * } * ] * } */
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?