Search.../

getPlanStats( )

Retrieves statistics about the pricing plans.

Description

The getPlanStats() function returns a Promise that resolves to statistics about the plan on the site.

Currently this function provides only the total number of pricing plans, including archived plans.

Admin Method

This function requires elevated permissions to run. This function is not universal and runs only on the backend.

Syntax

function getPlanStats(): Promise<GetPlanStatsResponse>

getPlanStats Parameters

This function does not take any parameters.

Returns

Fulfilled - Overall statistics about the pricing plans.

Return Type:

Promise<
GetPlanStatsResponse
>
NAME
TYPE
DESCRIPTION
totalPlans
number

Total number of plans created, including active plans (both public and hidden) and archived plans.

Was this helpful?

Get number of plans (dashboard page code)

Copy Code
1import { plans } from 'wix-pricing-plans.v2';
2
3export async function myGetPlanStatsFunction() {
4 try {
5 const planStats = plans.getPlanStats();
6
7 return planStats;
8 } catch (error) {
9 console.error(error);
10 // Handle the error
11 }
12}
13
14/* Promise resolves to:
15 * {
16 * "totalPlans": 8
17 * }
18 */
Get number of plans (export from backend code)

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { plans } from 'wix-pricing-plans.v2';
3import { elevate } from 'wix-auth';
4
5export const myGetPlanStatsFunction = webMethod(Permissions.Anyone, async () => {
6 try {
7 const elevatedGetPlanStats = elevate(plans.getPlanStats);
8 const planStats = elevatedGetPlanStats();
9
10 return planStats;
11 } catch (error) {
12 console.error(error);
13 // Handle the error
14 }
15});
16
17/* Promise resolves to:
18 * {
19 * "totalPlans": 8
20 * }
21 */
22