Checking the Member Plan status then show or hide button

How do check the status of a member plan then show or hide a button?
Thanks

You can simply use Wix Users API to check the current users pricing plan and then use code to show or hide the button depending on what you want it to do for that member plan or not that member plan.
https://www.wix.com/corvid/reference/wix-users.html

Something like this for example.

import wixUsers from 'wix-users';

$w.onReady(function () {

let user = wixUsers.currentUser;
let userId = user.id;
let isLoggedIn = user.loggedIn;

user.getPricingPlans()
.then( (pricingPlans) => {
let firstPlan = pricingPlans[0];
let planName = firstPlan.name;

if (planName === "Basic Plan") {
$w("#eventtype").disable();
$w("#specialrequests").disable();
$w("#errormessage1").show();
}
else {
$w("#eventtype").enable();
$w("#specialrequests").enable();
$w("#errormessage1").hide();
}}
)})

Thanks for replying, the problem is that when the customer has 2 plans, the code always return the first plan even when it is expired
I am tried to use the following code to display the active code but it does not work

let firstPlan = pricingPlans[0];
let planName = [firstPlan.name;](firstPlan.name;
let)
[let](firstPlan.name;
let) planStatus = firstPlan.status;
if ((planName === “Basic Plan”) && (planStatus === “Active”)) {
$w(“#eventtype”).disable();
$w(“#specialrequests”).disable();

I also tried the Starting date and the date that the plan expired but it does not return the ACTIVE PLAN

wixUsers.currentUser.getPricingPlans()
.then((PaidPlans) => {
if (PaidPlans.length > 0) {
let firstPlan = PaidPlans[0];
let planName = firstPlan.name;
let startDate = firstPlan.startDate;
let expiryDate = firstPlan.expiryDate;
let currentDate = new Date();
if ((planName === “Basic Plan”) && (expiryDate > currentDate)) {
$w(“#eventtype”).show();
$w(“#specialrequests”).disable();

Any help!!! Thanks

Yes that is because getPricingPlan is asynchronous, so it won’t return a value to you immediately. That is why the code has a .then(), the code in the .then() is only run after the promise returned by .getPricingPlan() resolves to a value.

Wix do a good page about using promises and asynchronous code here.
https://support.wix.com/en/article/corvid-working-with-promises

The code where you check if the pricingPlan is “Basic Plan” actually runs before the code where you set the value of pricingPlan. That’s why it doesn’t work. You need to pull that code up into the .then().

Alternatively, you can use async/await to deal with the asynchronous code.

Note that this still doesn’t work because you are only checking the users first plan. If the user has multiple plans then there is no guarantee that “Basic Plan” will be the first plan.

If you are wanting to do something for multiple plans, then have a look at previous posts like this one linked below and simply alter it for getPricingPlans and not getRoles,
https://www.wix.com/corvid/forum/community-discussion/use-role-not-accessible-on-code