Get paid plans of a user ID

For example: everything I have is user’s ID and I need to know which paid plans this user has.

When I use getUser(userID) in backend, it returns object of type UserInfo, which doesn’t have a function called getPricingPlans().

Basically what I’m doing is, I’m querying all the users from the database (Members/PrivateMembersData) and I need to know which pricing plans everyone of those users has.

Is there any way of achieving this?

Or is there any type of query that would return all users by a specific plan? For example: return all users with gold plan.

Hi
You can use the wix-paid-plans API for that
https://www.wix.com/corvid/reference/wix-paid-plans.html
But unfortunately, only to be used on page side, not on backend side. From here you can iterate on orders with a forEach for example and select on .planName.


import wixPaidPlans from 'wix-paid-plans';

async function displayOrders() {
let orders = await wixPaidPlans.getCurrentMemberOrders()
...
}

But this code you provided returns plans of currently logged in user. I need to return plans of every user in the database.

Ah I see. You can’t. Two workarounds :
Solution 1: The Wix User Dashboard
Paid Plans > Purchased Plans >
Here you can filter in field Display the members that ordered Gold. You can filter on active users too if you want

Solution 2: Build your own Paid Plans back-end or use another Wi-App where you can do this.

Hmmm… Is there a “plan expired” or “plan cancelled” event, that would be called in backend?

@jirkaparmenhulmik no only the onPurchase event you can use (or at least this is the only one in the API). But the cancel is something you can trigger yourself. If a user cancels his plan, you do this by coding on page side anyway (cancelOrder), you can hook up in that function to do any logic you want. The expire unfortunately is not possible.

If you want to use those events to send out mailings I do know that the WIx User Dashboard gives you through Customer Manager > Automations, the possibility to mail a user on many events. The Expire and Cancel event is foreseen there. So I have no clue why this isn’t in the API. Perhaps you can read:
https://www.wix.com/corvid/reference/wix-paid-plans-backend.Events.html
You could try (without any guarantee) to see if one of these events work : onPlanCancellation, onPlanCancel, onPlanExpire, onPlanExpiration, onPlanExpired…
If its succesfull, please let me know :wink:

@hemisphere81 onPlanCancellation and onPlanCancel doesn’t seem to work :confused: Basically what I’m trying to achieve is, to send an email to ALL users with a certain plan (gold or silver or whatever). Is there a way for that at least in control panel? I need to figure out how to achieve this, otherwise I’m kinda screwed

@jirkaparmenhulmik

If you are using getUser(id) from the Wix Users Backend API, then it will only return the UserInfo and none of the users roles or plans etc.

If all you are wanting to do is to send an email to all your users with a certain plan, then you can just use the Wix Users Backend API with the emailUsers function to email all those specific members.

You will have to first time manually insert the userId of all those members with a specific plan, however you can easily just get this from your dataset and you will only need to do it once, just making sure that you add or remove any member who adds a plan or ends a plan etc.

How do I send an email to a user who is not the currently logged-in user?

Using the emailUser() function of wix-users you can only send emails to the currently logged-in user.

However, from the backend, using the emailUser() function of wix-users-backend you can send emails to any site member.

The Wix Automations for Paid Plans are already setup for you, however you can change the design of them to suit your own site.
https://support.wix.com/en/article/sending-automated-emails-in-paid-plans

You can send an automated email every time:

  • A client purchases a paid plan

  • A purchased plan gets close to expiring

  • A plan expires

  • A plan is canceled

  • A client has used all the sessions in a package

To save you time, these automations are already set up (but you may need to activate them). Feel free to use them with the recommended default settings or customize the text, design, and timing to suit your needs.

Automated emails are sent through Wix Automations.

Pre-Installed Automations
Some Wix Apps (e.g. Paid Plans, Workflows) come with automations which have been designed and pre-installed for you. These automations start working as soon as you add the relevant Wix App. Learn More

You can also use Wix Paid Plans API if you want to let users cancel their plan.
https://www.wix.com/corvid/reference/wix-paid-plans.html#cancelOrder

@givemeawhisky “First time manually insert the userId of all those members with a specific plan” You mean to manually add every userId of a user with a specific plan to a dataset and then send an email to everyone in that dataset?

No, you simply get the userId of all the members with gold for example and then add them to the email user function in the Wix Users Backend API.
https://www.wix.com/corvid/reference/wix-users-backend.html#emailUser

Just make sure that you keep these up to date with added any new plan members or to remove those who have cancelled the plan etc.

Examples

Send a Triggered Email to a site member

import wixUsersBackend from 'wix-users-backend';

export function myBackendFunction() {
  let userId = // get user ID

  wixUsersBackend.emailUser("emailID", userId)
    .then( () => {
      // email has been sent
    } )
    .catch( (err) => {
      // there was an error sending the email
  } );
}

Send a Triggered Email to a site member with variable values

import wixUsersBackend from 'wix-users-backend';

export function myBackendFunction() {
  let userId = // get user ID
  let value1 = // value for variable1

  wixUsersBackend.emailUser("emailID", userId, {
      "variables": {
        "variable1": value1,
        "variable2": "value for variable2"
      }
    } )
    .then( () => {
      // email has been sent
    } )
    .catch( (err) => {
      // there was an error sending the email
    } );
}

@givemeawhisky Sending an email to a specific user by his ID is not a problem for me, but what I need, is how do I “simply get the userId of all the members with gold for example”?

@jirkaparmenhulmik
Ah well this is where hindsight is a wonderful thing!

If you had made some custom labels in your Contact List for each of your current paid plans, then you could have just assigned that label to the appropriate user. You could have just viewed by that plan label and made a note of all the members that were using that paid plan. **

Followed by going through the Wix members app collection and getting each of those members unique userId.

Then you just add it to your email user code and depending on how many paid plans and plan users you have already got, this will either be a piece of cake or a long and boring procedure.

Once this is done the first and only time, then all you would need to do is to make sure that you update it with a new userId if somebody adds that paid plan or remove a userId if somebody cancels that paid plan.

** You can also look in your own Paid Plan settings as well instead of adding contact labels to save you some time with this and view all the specific plan users in your Purchased Plans tab
https://support.wix.com/en/article/viewing-and-managing-paid-plans-that-clients-purchased

@jirkaparmenhulmik plans are member and thus userbased. You can filter them in the dashboard but you can export them like you can in contacts. So one option: if a customer purchases a plan, you can set a Label in OnPlanPurchase. You can use this API for that.
https://www.wix.com/corvid/reference/wix-crm-backend.html#updateContact
At least then you can export them, or you can use the Wix Marketing tool to do so. Which is nice as well.
Only thing you have to do for your existing member is to set this property manually.

or again
Solution 2: have everything custom build yourself.

So glad I found this thread.

I’m trying to display all plans for a currently logged in user. The following code shows one plan (since I couldn’t figure out how to list all plans, I listed the most recent one). I haven’t tried putting a repeater or table on the page to show all. (I’d need help with that since you normally connect the data collection where the current member orders reside. CurrentMemberOrders is not listed as an available data collection to connect.)

This is what I have in on Ready:

wixUsers.currentUser.getPricingPlans()  //put offset in parenthesis; to go to 2nd plan, put 1.
            .then((pricingPlans) => {
 let currentPlan = pricingPlans[pricingPlans.length - 1];
 let planName = currentPlan.name;
 let qprice = currentPlan.price;
 //let benefits = currentPlan.benefits;
 //let sdate = currentPlan.startDate;
 let eDate = currentPlan.expiryDate;

                $w('#PlanName').value = currentPlan.name;
                $w('#Price').value = currentPlan.price;
                $w('#ExpirationDate').value = currentPlan.expiryDate.toDateString();

            });

        wixPaidPlans.getCurrentMemberOrders() ////put offset in parenthesis; to go to 2nd plan, put 1.
 //function getCurrentMemberOrders([offset: number], [limit: number]): Array<Order>
            .then((pricingPlans) => {
 let currentPlan = pricingPlans[pricingPlans.length - 1];
                $w('#PlanStatus').value = currentPlan.status;
            })

This is what is displayed for me (I’m a member and an Admin). If I can show all plans, I’m hoping I’ll see the plan I paid for as a member. And this is our second year for plans so I want members to see both years.

Below is what shows for a test user. I bought a $0 plan so I didn’t have to actually pay for something in my test:

If there is a paid plan, will the amount show up? Is there a way to display $0 plans?

Thanks in advance for any guidance you can provide!

It doesn’t exist. Vote here : https://www.wix.com/velo/requested-feature/back-end-function-for-getprincingplan

Use For Loop to get all plan details

I know this is an old thread but I have the same issue. Puting let orders = await wixPaidPlans . getCurrentMemberOrders () in a loop would just return the same information for the current user over and over again as there doesn’t appear to be a way to index through different users.