Search.../

queryPublicPlans( )

Creates a query to retrieve a list of public pricing plans.

Description

The queryPublicPlans() function builds a query to retrieve a list of up to 1,000 public plans and returns a PublicPlansQueryBuilder object.

The returned object contains the query definition which is typically used to run the query using the find() function.

You can refine the query by chaining PublicPlansQueryBuilder functions onto the query. PublicPlansQueryBuilder functions enable you to sort, filter, and control the results that queryPublicPlans() returns.

queryPublicPlans() runs with the following PublicPlansQueryBuilder defaults that you can override:

The functions that are chained to queryPublicPlans() are applied in the order they are called. For example, if you sort on the _createdDate property in ascending order and then on the _id property in ascending order, the results are sorted first by the created date of the items and then, if there are multiple results with the same date, the items are sorted by _id in ascending order, per created date value.

The following PublicPlansQueryBuilder functions are supported for the queryPublicPlans() function. For a full description of the Plans object, see the object returned for the items property in PublicPlansQueryResult.

PROPERTYSUPPORTED FILTERS & SORTING
_ideq(),ne(),exists(),in(),hasSome(),startsWith(),ascending(),descending()
primaryeq(),ne(),exists(),in(),hasSome(),ascending(),descending()
_createdDateeq(),ne(),exists(),in(),hasSome(),lt(),le(),gt(),ge(),ascending(),descending()
_updatedDateeq(),ne(),exists(),in(),hasSome(),lt(),le(),gt(),ge(),ascending(),descending()
slugeq(),ne(),exists(),in(),hasSome(),startsWith(),ascending(),descending()

Syntax

function queryPublicPlans(): PlansQueryBuilder

queryPublicPlans Parameters

This function does not take any parameters.

Returns

Return Type:

Was this helpful?

Build and execute a query to find all public plans

Copy Code
1import { plans } from 'wix-pricing-plans.v2';
2
3export async function myQueryPublicPlansFunction() {
4 try {
5 const results = await plans.queryPublicPlans().find();
6 const items = results.items;
7 const firstItem = items[0];
8 const length = results.length;
9 const currentPage = results.currentPage;
10
11 return items;
12 } catch (error) {
13 console.error(error);
14 // Handle the error
15 }
16}
17
18/* Returned items:
19 * [
20 * {
21 * "_createdDate": "2024-01-07T08:18:16.411Z",
22 * "_id": "7a3375ce-18a9-42cb-8e39-47918ade45ec",
23 * "_updatedDate": "2024-01-07T08:18:16.411Z",
24 * "allowFutureStartDate": false,
25 * "archived": false,
26 * "buyerCanCancel": true,
27 * "description": "Affordable with great functionality. Expires after 1 year",
28 * "hasOrders": false,
29 * "maxPurchasesPerBuyer": 0,
30 * "name": "Basic Plan - monthly subscription",
31 * "perks": {
32 * "values": [
33 * "Access to select video channels",
34 * "Access to rich site content",
35 * "Access to designated file store"
36 * ]
37 * },
38 * "primary": false,
39 * "pricing": {
40 * "cycleCount": 12,
41 * "cycleDuration": {
42 * "count": 1,
43 * "unit": "MONTH"
44 * },
45 * "price": {
46 * "currency": "EUR",
47 * "value": "5"
48 * },
49 * "subscription": {
50 * "cycleCount": 12,
51 * "cycleDuration": {
52 * "count": 1,
53 * "unit": "MONTH"
54 * }
55 * }
56 * },
57 * "slug": "basic-plan-monthly-subscription",
58 * "termsAndConditions": ""
59 * },
60 * {
61 * "_createdDate": "2024-01-07T07:10:30.074Z",
62 * "_id": "cb4a8c57-273a-4567-94e3-cc43d5d339f2",
63 * "_updatedDate": "2024-01-07T07:10:30.074Z",
64 * "allowFutureStartDate": false,
65 * "archived": false,
66 * "buyerCanCancel": true,
67 * "description": "3 mo free trial with discount for 1 year",
68 * "hasOrders": false,
69 * "maxPurchasesPerBuyer": 0,
70 * "name": "Beginner's Plan",
71 * "perks": {
72 * "values": []
73 * },
74 * "primary": false,
75 * "pricing": {
76 * "cycleCount": 2,
77 * "cycleDuration": {
78 * "count": 1,
79 * "unit": "YEAR"
80 * },
81 * "freeTrialDays": 90,
82 * "price": {
83 * "currency": "EUR",
84 * "value": "50"
85 * },
86 * "subscription": {
87 * "cycleCount": 2,
88 * "cycleDuration": {
89 * "count": 1,
90 * "unit": "YEAR"
91 * }
92 * }
93 * },
94 * "slug": "beginners-plan",
95 * "termsAndConditions": ""
96 * },
97 * {
98 * "_createdDate": "2024-01-07T07:28:42.863Z",
99 * "_id": "838f2c9d-c8d0-4799-a10a-e2f23849db10",
100 * "_updatedDate": "2024-01-07T08:36:07.520Z",
101 * "allowFutureStartDate": false,
102 * "archived": false,
103 * "buyerCanCancel": true,
104 * "description": "Complete with all features. One month free trial.",
105 * "hasOrders": false,
106 * "maxPurchasesPerBuyer": 0,
107 * "name": "Premium Plan - annual - 30 day trial",
108 * "perks": {
109 * "values": [
110 * "Unlimited video library streaming access",
111 * "File sharing enabled for all channels"
112 * ]
113 * },
114 * "primary": false,
115 * "pricing": {
116 * "cycleCount": 2,
117 * "cycleDuration": {
118 * "count": 1,
119 * "unit": "YEAR"
120 * },
121 * "freeTrialDays": 30,
122 * "price": {
123 * "currency": "EUR",
124 * "value": "500"
125 * },
126 * "subscription": {
127 * "cycleCount": 2,
128 * "cycleDuration": {
129 * "count": 1,
130 * "unit": "YEAR"
131 * }
132 * }
133 * },
134 * "slug": "premium-plan-annual-30-day-trial-1",
135 * "termsAndConditions": "Unlimited usage of services, subject to Fair Usage and Code of Conduct policies."
136 * },
137 * {
138 * "_createdDate": "2024-01-07T07:33:59.973Z",
139 * "_id": "b20feb39-a452-453e-96ee-01036adcd04e",
140 * "_updatedDate": "2024-01-09T09:08:05.665Z",
141 * "allowFutureStartDate": false,
142 * "archived": false,
143 * "buyerCanCancel": true,
144 * "description": "Full feature enablement - lifetime plan",
145 * "hasOrders": false,
146 * "maxPurchasesPerBuyer": 0,
147 * "name": "Premium Plan - Lifetime Membership",
148 * "perks": {
149 * "values": [
150 * "Cloud drive and file upload services",
151 * "Unlimited video content access"
152 * ]
153 * },
154 * "primary": false,
155 * "pricing": {
156 * "currency": "EUR",
157 * "value": "1000",
158 * "singlePaymentUnlimited": true
159 * },
160 * "slug": "premium-plan-lifetime-membership",
161 * "termsAndConditions": "This plan allows unlimited app and site features usage for all time, subject to our fair usage agreement and basic human decency agreement."
162 * },
163 * {
164 * "_createdDate": "2024-01-08T14:33:12.209Z",
165 * "_id": "d2fa5805-0d1a-4cfb-9b43-e683cf5fa990",
166 * "_updatedDate": "2024-01-08T14:33:12.209Z",
167 * "allowFutureStartDate": false,
168 * "archived": false,
169 * "buyerCanCancel": true,
170 * "description": "The value plan",
171 * "hasOrders": false,
172 * "maxPurchasesPerBuyer": 1,
173 * "name": "Silver Membership - Monthly",
174 * "perks": {
175 * "values": [
176 * "Full site access",
177 * "Full video access",
178 * "Consultation booking"
179 * ]
180 * },
181 * "primary": false,
182 * "pricing": {
183 * "currency": "EUR",
184 * "value": "100",
185 * "freeTrialDays": 14,
186 * "subscription": {
187 * "cycleCount": 0,
188 * "cycleDuration": {
189 * "count": 1,
190 * "unit": "MONTH"
191 * }
192 * }
193 * },
194 * "slug": "silver-membership-monthly",
195 * "termsAndConditions": ""
196 * }
197 * ]
198 */
Build and execute a query to find all public plans (export from backend code)

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { plans } from 'wix-pricing-plans.v2';
3
4export const myQueryPublicPlansFunction = webMethod(Permissions.Anyone, async () => {
5 try {
6 const results = await plans.queryPublicPlans().find();
7 const items = results.items;
8 const firstItem = items[0];
9 const length = results.length;
10 const currentPage = results.currentPage;
11
12 return items;
13 } catch (error) {
14 console.error(error);
15 // Handle the error
16 }
17});
18
19/* Returned items:
20 * [
21 * {
22 * "_createdDate": "2024-01-07T08:18:16.411Z",
23 * "_id": "7a3375ce-18a9-42cb-8e39-47918ade45ec",
24 * "_updatedDate": "2024-01-07T08:18:16.411Z",
25 * "allowFutureStartDate": false,
26 * "archived": false,
27 * "buyerCanCancel": true,
28 * "description": "Affordable with great functionality. Expires after 1 year",
29 * "hasOrders": false,
30 * "maxPurchasesPerBuyer": 0,
31 * "name": "Basic Plan - monthly subscription",
32 * "perks": {
33 * "values": [
34 * "Access to select video channels",
35 * "Access to rich site content",
36 * "Access to designated file store"
37 * ]
38 * },
39 * "primary": false,
40 * "pricing": {
41 * "cycleCount": 12,
42 * "cycleDuration": {
43 * "count": 1,
44 * "unit": "MONTH"
45 * },
46 * "price": {
47 * "currency": "EUR",
48 * "value": "5"
49 * },
50 * "subscription": {
51 * "cycleCount": 12,
52 * "cycleDuration": {
53 * "count": 1,
54 * "unit": "MONTH"
55 * }
56 * }
57 * },
58 * "slug": "basic-plan-monthly-subscription",
59 * "termsAndConditions": ""
60 * },
61 * {
62 * "_createdDate": "2024-01-07T07:10:30.074Z",
63 * "_id": "cb4a8c57-273a-4567-94e3-cc43d5d339f2",
64 * "_updatedDate": "2024-01-07T07:10:30.074Z",
65 * "allowFutureStartDate": false,
66 * "archived": false,
67 * "buyerCanCancel": true,
68 * "description": "3 mo free trial with discount for 1 year",
69 * "hasOrders": false,
70 * "maxPurchasesPerBuyer": 0,
71 * "name": "Beginner's Plan",
72 * "perks": {
73 * "values": []
74 * },
75 * "primary": false,
76 * "pricing": {
77 * "cycleCount": 2,
78 * "cycleDuration": {
79 * "count": 1,
80 * "unit": "YEAR"
81 * },
82 * "freeTrialDays": 90,
83 * "price": {
84 * "currency": "EUR",
85 * "value": "50"
86 * },
87 * "subscription": {
88 * "cycleCount": 2,
89 * "cycleDuration": {
90 * "count": 1,
91 * "unit": "YEAR"
92 * }
93 * }
94 * },
95 * "slug": "beginners-plan",
96 * "termsAndConditions": ""
97 * },
98 * {
99 * "_createdDate": "2024-01-07T07:28:42.863Z",
100 * "_id": "838f2c9d-c8d0-4799-a10a-e2f23849db10",
101 * "_updatedDate": "2024-01-07T08:36:07.520Z",
102 * "allowFutureStartDate": false,
103 * "archived": false,
104 * "buyerCanCancel": true,
105 * "description": "Complete with all features. One month free trial.",
106 * "hasOrders": false,
107 * "maxPurchasesPerBuyer": 0,
108 * "name": "Premium Plan - annual - 30 day trial",
109 * "perks": {
110 * "values": [
111 * "Unlimited video library streaming access",
112 * "File sharing enabled for all channels"
113 * ]
114 * },
115 * "primary": false,
116 * "pricing": {
117 * "cycleCount": 2,
118 * "cycleDuration": {
119 * "count": 1,
120 * "unit": "YEAR"
121 * },
122 * "freeTrialDays": 30,
123 * "price": {
124 * "currency": "EUR",
125 * "value": "500"
126 * },
127 * "subscription": {
128 * "cycleCount": 2,
129 * "cycleDuration": {
130 * "count": 1,
131 * "unit": "YEAR"
132 * }
133 * }
134 * },
135 * "slug": "premium-plan-annual-30-day-trial-1",
136 * "termsAndConditions": "Unlimited usage of services, subject to Fair Usage and Code of Conduct policies."
137 * },
138 * {
139 * "_createdDate": "2024-01-07T07:33:59.973Z",
140 * "_id": "b20feb39-a452-453e-96ee-01036adcd04e",
141 * "_updatedDate": "2024-01-09T09:08:05.665Z",
142 * "allowFutureStartDate": false,
143 * "archived": false,
144 * "buyerCanCancel": true,
145 * "description": "Full feature enablement - lifetime plan",
146 * "hasOrders": false,
147 * "maxPurchasesPerBuyer": 0,
148 * "name": "Premium Plan - Lifetime Membership",
149 * "perks": {
150 * "values": [
151 * "Cloud drive and file upload services",
152 * "Unlimited video content access"
153 * ]
154 * },
155 * "primary": false,
156 * "pricing": {
157 * "currency": "EUR",
158 * "value": "1000",
159 * "singlePaymentUnlimited": true
160 * },
161 * "slug": "premium-plan-lifetime-membership",
162 * "termsAndConditions": "This plan allows unlimited app and site features usage for all time, subject to our fair usage agreement and basic human decency agreement."
163 * },
164 * {
165 * "_createdDate": "2024-01-08T14:33:12.209Z",
166 * "_id": "d2fa5805-0d1a-4cfb-9b43-e683cf5fa990",
167 * "_updatedDate": "2024-01-08T14:33:12.209Z",
168 * "allowFutureStartDate": false,
169 * "archived": false,
170 * "buyerCanCancel": true,
171 * "description": "The value plan",
172 * "hasOrders": false,
173 * "maxPurchasesPerBuyer": 1,
174 * "name": "Silver Membership - Monthly",
175 * "perks": {
176 * "values": [
177 * "Full site access",
178 * "Full video access",
179 * "Consultation booking"
180 * ]
181 * },
182 * "primary": false,
183 * "pricing": {
184 * "currency": "EUR",
185 * "value": "100",
186 * "freeTrialDays": 14,
187 * "subscription": {
188 * "cycleCount": 0,
189 * "cycleDuration": {
190 * "count": 1,
191 * "unit": "MONTH"
192 * }
193 * }
194 * },
195 * "slug": "silver-membership-monthly",
196 * "termsAndConditions": ""
197 * }
198 * ]
199 */
200
Build and execute query to retrieve primary plan

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { plans } from 'wix-pricing-plans.v2';
3
4export const myQueryPublicPlansFunction = webMethod(Permissions.Anyone, async () => {
5 try {
6 const results =
7 await plans.queryPublicPlans()
8 .eq('primary', true)
9 .find();
10 const primaryPlan = results.items[0];
11
12 return primaryPlan;
13 } catch (error) {
14 console.error(error);
15 // Handle the error
16 }
17});
18
19/* Returned item:
20 * {
21 * "_createdDate": "2024-01-07T07:28:42.863Z",
22 * "_id": "838f2c9d-c8d0-4799-a10a-e2f23849db10",
23 * "_updatedDate": "2024-01-16T12:19:54.617Z",
24 * "allowFutureStartDate": false,
25 * "buyerCanCancel": true,
26 * "description": "Complete with all features. One month free trial.",
27 * "maxPurchasesPerBuyer": 0,
28 * "perks": {
29 * "values": [
30 * "Unlimited video library streaming access",
31 * "File sharing enabled for all channels"
32 * ]
33 * },
34 * "primary": true,
35 * "pricing": {
36 * "freeTrialDays": 30,
37 * "price": {
38 * "currency": "EUR",
39 * "value": "500"
40 * },
41 * "subscription": {
42 * "cycleCount": 2,
43 * "cycleDuration": {
44 * "count": 1,
45 * "unit": "YEAR"
46 * }
47 * }
48 * },
49 * "slug": "premium-plan-annual-30-day-trial-1",
50 * "termsAndConditions": "Unlimited usage of services, subject to Fair Usage and Code of Conduct policies."
51 * }
52 */
53
Build and execute a query for a specific plan ID given its slug

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { plans } from 'wix-pricing-plans.v2';
3
4export const myQueryPublicPlansFunction4 = webMethod(Permissions.Anyone, async () => {
5 try {
6 const results =
7 await plans.queryPublicPlans()
8 .eq('slug','basic-plan-monthly-subscription')
9 .find();
10 const planId = results.items[0]._id;
11
12 return planId;
13 } catch(error) {
14 console.error(error);
15 // Handle the error
16 }
17});
18
19/* Returned item: '7a3375ce-18a9-42cb-8e39-47918ade45ec' */
20
Sort plans alphabetically

Select a sorting option to arranage plans in ascending or descending order by plan slug.

Copy Code
1/*************************************
2 * Backend code - plan-functions.web.js *
3 *************************************/
4
5import { Permissions, webMethod } from 'wix-web-module';
6import { plans } from 'wix-pricing-plans.v2';
7import { elevate } from 'wix-auth';
8
9const elevatedArrangePlans = elevate(plans.arrangePlans);
10
11export const sortPlansBySlug = webMethod(Permissions.Anyone, async (direction) => {
12 let publicPlansQuery = plans.queryPublicPlans();
13
14 if (direction === 'ascending') {
15 publicPlansQuery = publicPlansQuery.ascending('slug');
16 } else {
17 publicPlansQuery = publicPlansQuery.descending('slug');
18 }
19
20 const sortedPlans = await publicPlansQuery.find();
21 const planIds = sortedPlans.items.map(item => item._id);
22
23 return await elevatedArrangePlans(planIds);
24});
25
26/*************
27 * Page code *
28 *************/
29
30import { sortPlansBySlug } from 'backend/plan-functions.web';
31import wixLocationFrontend from 'wix-location-frontend';
32
33$w.onReady(function () {
34 $w('#dropdownSort').options =
35 [
36 {
37 label: 'Ascending',
38 value: 'ascending'
39 },
40 {
41 label: 'Decending',
42 value: 'descending'
43 }
44 ];
45
46 $w('#dropdownSort').onChange(async () => {
47 const direction = $w('#dropdownSort').value;
48 sortPlansBySlug(direction);
49 const url = wixLocationFrontend.url;
50 wixLocationFrontend.to(url);
51 })
52});
53