> 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: queryPublicPlans() # Method package: wixPricingPlansV2 # Method menu location: wixPricingPlansV2 --> plans --> queryPublicPlans # Method Link: https://dev.wix.com/docs/velo/apis/wix-pricing-plans-v2/plans/query-public-plans.md # Method Description: Creates a query to retrieve a list of public pricing plans. The `queryPublicPlans()` method builds a query to retrieve a list of up to 1,000 public plans and returns a [`PublicPlansQueryBuilder`](#plansquerybuilder) object. The returned object contains the query definition which is typically used to run the query using the [`find()`](#plansquerybuilder/find) method. You can refine the query by chaining `PublicPlansQueryBuilder` methods onto the query. `PublicPlansQueryBuilder` methods enable you to sort, filter, and control the results that `queryPublicPlans()` returns. `queryPublicPlans()` runs with the following `PublicPlansQueryBuilder` defaults that you can override: - [`skip`](#plansquerybuilder/skip): `0` - [`limit`](#plansquerybuilder/limit): `50` The methods 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` methods are supported for the `queryPublicPlans()` method. For a full description of the Plans object, see the object returned for the [`items`](#plansqueryresult/items) property in [`PublicPlansQueryResult`](#plansqueryresult). |PROPERTY |SUPPORTED FILTERS & SORTING |:---:|:---:| |`_id`|[`eq()`](/plans-query-builder/eq),[`ne()`](/plans-query-builder/ne),[`exists()`](/plans-query-builder/exists),[`in()`](/plans-query-builder/in),[`hasSome()`](/plans-query-builder/has-some),[`startsWith()`](/plans-query-builder/starts-with),[`ascending()`](/plans-query-builder/ascending),[`descending()`](/plans-query-builder/descending)| |`primary`|[`eq()`](/plans-query-builder/eq),[`ne()`](/plans-query-builder/ne),[`exists()`](/plans-query-builder/exists),[`in()`](/plans-query-builder/in),[`hasSome()`](/plans-query-builder/has-some),[`ascending()`](/plans-query-builder/ascending),[`descending()`](/plans-query-builder/descending)| |`_createdDate`|[`eq()`](/plans-query-builder/eq),[`ne()`](/plans-query-builder/ne),[`exists()`](/plans-query-builder/exists),[`in()`](/plans-query-builder/in),[`hasSome()`](/plans-query-builder/has-some),[`lt()`](/plans-query-builder/lt),[`le()`](/plans-query-builder/le),[`gt()`](/plans-query-builder/gt),[`ge()`](/plans-query-builder/ge),[`ascending()`](/plans-query-builder/ascending),[`descending()`](/plans-query-builder/descending)| |`_updatedDate`|[`eq()`](/plans-query-builder/eq),[`ne()`](/plans-query-builder/ne),[`exists()`](/plans-query-builder/exists),[`in()`](/plans-query-builder/in),[`hasSome()`](/plans-query-builder/has-some),[`lt()`](/plans-query-builder/lt),[`le()`](/plans-query-builder/le),[`gt()`](/plans-query-builder/gt),[`ge()`](/plans-query-builder/ge),[`ascending()`](/plans-query-builder/ascending),[`descending()`](/plans-query-builder/descending)| |`slug`|[`eq()`](/plans-query-builder/eq),[`ne()`](/plans-query-builder/ne),[`exists()`](/plans-query-builder/exists),[`in()`](/plans-query-builder/in),[`hasSome()`](/plans-query-builder/has-some),[`startsWith()`](/plans-query-builder/starts-with),[`ascending()`](/plans-query-builder/ascending),[`descending()`](/plans-query-builder/descending)| # Method Code Examples: *** Note: do not assume any prop names or enum values other than the ones in the example. ## Build and execute a query to find all public plans ```javascript import { plans } from 'wix-pricing-plans.v2'; export async function myQueryPublicPlansFunction() { try { const results = await plans.queryPublicPlans().find(); const items = results.items; const firstItem = items[0]; const length = results.length; const currentPage = results.currentPage; return items; } catch (error) { console.error(error); // Handle the error } } /* Returned items: * [ * { * "_createdDate": "2024-01-07T08:18:16.411Z", * "_id": "7a3375ce-18a9-42cb-8e39-47918ade45ec", * "_updatedDate": "2024-01-07T08:18:16.411Z", * "allowFutureStartDate": false, * "archived": false, * "buyerCanCancel": true, * "description": "Affordable with great functionality. Expires after 1 year", * "hasOrders": false, * "maxPurchasesPerBuyer": 0, * "name": "Basic Plan - monthly subscription", * "perks": { * "values": [ * "Access to select video channels", * "Access to rich site content", * "Access to designated file store" * ] * }, * "primary": false, * "pricing": { * "cycleCount": 12, * "cycleDuration": { * "count": 1, * "unit": "MONTH" * }, * "price": { * "currency": "EUR", * "value": "5" * }, * "subscription": { * "cycleCount": 12, * "cycleDuration": { * "count": 1, * "unit": "MONTH" * } * } * }, * "slug": "basic-plan-monthly-subscription", * "termsAndConditions": "" * }, * { * "_createdDate": "2024-01-07T07:10:30.074Z", * "_id": "cb4a8c57-273a-4567-94e3-cc43d5d339f2", * "_updatedDate": "2024-01-07T07:10:30.074Z", * "allowFutureStartDate": false, * "archived": false, * "buyerCanCancel": true, * "description": "3 mo free trial with discount for 1 year", * "hasOrders": false, * "maxPurchasesPerBuyer": 0, * "name": "Beginner's Plan", * "perks": { * "values": [] * }, * "primary": false, * "pricing": { * "cycleCount": 2, * "cycleDuration": { * "count": 1, * "unit": "YEAR" * }, * "freeTrialDays": 90, * "price": { * "currency": "EUR", * "value": "50" * }, * "subscription": { * "cycleCount": 2, * "cycleDuration": { * "count": 1, * "unit": "YEAR" * } * } * }, * "slug": "beginners-plan", * "termsAndConditions": "" * }, * { * "_createdDate": "2024-01-07T07:28:42.863Z", * "_id": "838f2c9d-c8d0-4799-a10a-e2f23849db10", * "_updatedDate": "2024-01-07T08:36:07.520Z", * "allowFutureStartDate": false, * "archived": false, * "buyerCanCancel": true, * "description": "Complete with all features. One month free trial.", * "hasOrders": false, * "maxPurchasesPerBuyer": 0, * "name": "Premium Plan - annual - 30 day trial", * "perks": { * "values": [ * "Unlimited video library streaming access", * "File sharing enabled for all channels" * ] * }, * "primary": false, * "pricing": { * "cycleCount": 2, * "cycleDuration": { * "count": 1, * "unit": "YEAR" * }, * "freeTrialDays": 30, * "price": { * "currency": "EUR", * "value": "500" * }, * "subscription": { * "cycleCount": 2, * "cycleDuration": { * "count": 1, * "unit": "YEAR" * } * } * }, * "slug": "premium-plan-annual-30-day-trial-1", * "termsAndConditions": "Unlimited usage of services, subject to Fair Usage and Code of Conduct policies." * }, * { * "_createdDate": "2024-01-07T07:33:59.973Z", * "_id": "b20feb39-a452-453e-96ee-01036adcd04e", * "_updatedDate": "2024-01-09T09:08:05.665Z", * "allowFutureStartDate": false, * "archived": false, * "buyerCanCancel": true, * "description": "Full feature enablement - lifetime plan", * "hasOrders": false, * "maxPurchasesPerBuyer": 0, * "name": "Premium Plan - Lifetime Membership", * "perks": { * "values": [ * "Cloud drive and file upload services", * "Unlimited video content access" * ] * }, * "primary": false, * "pricing": { * "currency": "EUR", * "value": "1000", * "singlePaymentUnlimited": true * }, * "slug": "premium-plan-lifetime-membership", * "termsAndConditions": "This plan allows unlimited app and site features usage for all time, subject to our fair usage agreement and basic human decency agreement." * }, * { * "_createdDate": "2024-01-08T14:33:12.209Z", * "_id": "d2fa5805-0d1a-4cfb-9b43-e683cf5fa990", * "_updatedDate": "2024-01-08T14:33:12.209Z", * "allowFutureStartDate": false, * "archived": false, * "buyerCanCancel": true, * "description": "The value plan", * "hasOrders": false, * "maxPurchasesPerBuyer": 1, * "name": "Silver Membership - Monthly", * "perks": { * "values": [ * "Full site access", * "Full video access", * "Consultation booking" * ] * }, * "primary": false, * "pricing": { * "currency": "EUR", * "value": "100", * "freeTrialDays": 14, * "subscription": { * "cycleCount": 0, * "cycleDuration": { * "count": 1, * "unit": "MONTH" * } * } * }, * "slug": "silver-membership-monthly", * "termsAndConditions": "" * } * ] */ ``` ## Build and execute a query to find all public plans (export from backend code) ```javascript import { Permissions, webMethod } from 'wix-web-module'; import { plans } from 'wix-pricing-plans.v2'; export const myQueryPublicPlansFunction = webMethod(Permissions.Anyone, async () => { try { const results = await plans.queryPublicPlans().find(); const items = results.items; const firstItem = items[0]; const length = results.length; const currentPage = results.currentPage; return items; } catch (error) { console.error(error); // Handle the error } }); /* Returned items: * [ * { * "_createdDate": "2024-01-07T08:18:16.411Z", * "_id": "7a3375ce-18a9-42cb-8e39-47918ade45ec", * "_updatedDate": "2024-01-07T08:18:16.411Z", * "allowFutureStartDate": false, * "archived": false, * "buyerCanCancel": true, * "description": "Affordable with great functionality. Expires after 1 year", * "hasOrders": false, * "maxPurchasesPerBuyer": 0, * "name": "Basic Plan - monthly subscription", * "perks": { * "values": [ * "Access to select video channels", * "Access to rich site content", * "Access to designated file store" * ] * }, * "primary": false, * "pricing": { * "cycleCount": 12, * "cycleDuration": { * "count": 1, * "unit": "MONTH" * }, * "price": { * "currency": "EUR", * "value": "5" * }, * "subscription": { * "cycleCount": 12, * "cycleDuration": { * "count": 1, * "unit": "MONTH" * } * } * }, * "slug": "basic-plan-monthly-subscription", * "termsAndConditions": "" * }, * { * "_createdDate": "2024-01-07T07:10:30.074Z", * "_id": "cb4a8c57-273a-4567-94e3-cc43d5d339f2", * "_updatedDate": "2024-01-07T07:10:30.074Z", * "allowFutureStartDate": false, * "archived": false, * "buyerCanCancel": true, * "description": "3 mo free trial with discount for 1 year", * "hasOrders": false, * "maxPurchasesPerBuyer": 0, * "name": "Beginner's Plan", * "perks": { * "values": [] * }, * "primary": false, * "pricing": { * "cycleCount": 2, * "cycleDuration": { * "count": 1, * "unit": "YEAR" * }, * "freeTrialDays": 90, * "price": { * "currency": "EUR", * "value": "50" * }, * "subscription": { * "cycleCount": 2, * "cycleDuration": { * "count": 1, * "unit": "YEAR" * } * } * }, * "slug": "beginners-plan", * "termsAndConditions": "" * }, * { * "_createdDate": "2024-01-07T07:28:42.863Z", * "_id": "838f2c9d-c8d0-4799-a10a-e2f23849db10", * "_updatedDate": "2024-01-07T08:36:07.520Z", * "allowFutureStartDate": false, * "archived": false, * "buyerCanCancel": true, * "description": "Complete with all features. One month free trial.", * "hasOrders": false, * "maxPurchasesPerBuyer": 0, * "name": "Premium Plan - annual - 30 day trial", * "perks": { * "values": [ * "Unlimited video library streaming access", * "File sharing enabled for all channels" * ] * }, * "primary": false, * "pricing": { * "cycleCount": 2, * "cycleDuration": { * "count": 1, * "unit": "YEAR" * }, * "freeTrialDays": 30, * "price": { * "currency": "EUR", * "value": "500" * }, * "subscription": { * "cycleCount": 2, * "cycleDuration": { * "count": 1, * "unit": "YEAR" * } * } * }, * "slug": "premium-plan-annual-30-day-trial-1", * "termsAndConditions": "Unlimited usage of services, subject to Fair Usage and Code of Conduct policies." * }, * { * "_createdDate": "2024-01-07T07:33:59.973Z", * "_id": "b20feb39-a452-453e-96ee-01036adcd04e", * "_updatedDate": "2024-01-09T09:08:05.665Z", * "allowFutureStartDate": false, * "archived": false, * "buyerCanCancel": true, * "description": "Full feature enablement - lifetime plan", * "hasOrders": false, * "maxPurchasesPerBuyer": 0, * "name": "Premium Plan - Lifetime Membership", * "perks": { * "values": [ * "Cloud drive and file upload services", * "Unlimited video content access" * ] * }, * "primary": false, * "pricing": { * "currency": "EUR", * "value": "1000", * "singlePaymentUnlimited": true * }, * "slug": "premium-plan-lifetime-membership", * "termsAndConditions": "This plan allows unlimited app and site features usage for all time, subject to our fair usage agreement and basic human decency agreement." * }, * { * "_createdDate": "2024-01-08T14:33:12.209Z", * "_id": "d2fa5805-0d1a-4cfb-9b43-e683cf5fa990", * "_updatedDate": "2024-01-08T14:33:12.209Z", * "allowFutureStartDate": false, * "archived": false, * "buyerCanCancel": true, * "description": "The value plan", * "hasOrders": false, * "maxPurchasesPerBuyer": 1, * "name": "Silver Membership - Monthly", * "perks": { * "values": [ * "Full site access", * "Full video access", * "Consultation booking" * ] * }, * "primary": false, * "pricing": { * "currency": "EUR", * "value": "100", * "freeTrialDays": 14, * "subscription": { * "cycleCount": 0, * "cycleDuration": { * "count": 1, * "unit": "MONTH" * } * } * }, * "slug": "silver-membership-monthly", * "termsAndConditions": "" * } * ] */ ``` ## Build and execute query to retrieve primary plan ```javascript import { Permissions, webMethod } from 'wix-web-module'; import { plans } from 'wix-pricing-plans.v2'; export const myQueryPublicPlansFunction = webMethod(Permissions.Anyone, async () => { try { const results = await plans.queryPublicPlans() .eq('primary', true) .find(); const primaryPlan = results.items[0]; return primaryPlan; } catch (error) { console.error(error); // Handle the error } }); /* Returned item: * { * "_createdDate": "2024-01-07T07:28:42.863Z", * "_id": "838f2c9d-c8d0-4799-a10a-e2f23849db10", * "_updatedDate": "2024-01-16T12:19:54.617Z", * "allowFutureStartDate": false, * "buyerCanCancel": true, * "description": "Complete with all features. One month free trial.", * "maxPurchasesPerBuyer": 0, * "perks": { * "values": [ * "Unlimited video library streaming access", * "File sharing enabled for all channels" * ] * }, * "primary": true, * "pricing": { * "freeTrialDays": 30, * "price": { * "currency": "EUR", * "value": "500" * }, * "subscription": { * "cycleCount": 2, * "cycleDuration": { * "count": 1, * "unit": "YEAR" * } * } * }, * "slug": "premium-plan-annual-30-day-trial-1", * "termsAndConditions": "Unlimited usage of services, subject to Fair Usage and Code of Conduct policies." * } */ ``` ## Build and execute a query for a specific plan ID given its slug ```javascript import { Permissions, webMethod } from 'wix-web-module'; import { plans } from 'wix-pricing-plans.v2'; export const myQueryPublicPlansFunction4 = webMethod(Permissions.Anyone, async () => { try { const results = await plans.queryPublicPlans() .eq('slug','basic-plan-monthly-subscription') .find(); const planId = results.items[0]._id; return planId; } catch(error) { console.error(error); // Handle the error } }); /* Returned item: '7a3375ce-18a9-42cb-8e39-47918ade45ec' */ ``` ## Sort plans alphabetically ```javascript /************************************* * Backend code - plan-functions.web.js * *************************************/ import { Permissions, webMethod } from 'wix-web-module'; import { plans } from 'wix-pricing-plans.v2'; import { elevate } from 'wix-auth'; const elevatedArrangePlans = elevate(plans.arrangePlans); export const sortPlansBySlug = webMethod(Permissions.Anyone, async (direction) => { let publicPlansQuery = plans.queryPublicPlans(); if (direction === 'ascending') { publicPlansQuery = publicPlansQuery.ascending('slug'); } else { publicPlansQuery = publicPlansQuery.descending('slug'); } const sortedPlans = await publicPlansQuery.find(); const planIds = sortedPlans.items.map(item => item._id); return await elevatedArrangePlans(planIds); }); /************* * Page code * *************/ import { sortPlansBySlug } from 'backend/plan-functions.web'; import wixLocationFrontend from 'wix-location-frontend'; $w.onReady(function () { $w('#dropdownSort').options = [ { label: 'Ascending', value: 'ascending' }, { label: 'Decending', value: 'descending' } ]; $w('#dropdownSort').onChange(async () => { const direction = $w('#dropdownSort').value; sortPlansBySlug(direction); const url = wixLocationFrontend.url; wixLocationFrontend.to(url); }) }); ``` ---