So im trying to make some elements to be showed only for certain user that bought X Plan but it seems it doesn’t work
let user = wixUsers.currentUser; let isLoggedIn = user.loggedIn
user.getPricingPlans()
.then( (pricingPlans) => { let firstPlan = pricingPlans[0]; let planName = firstPlan.name; let startDate = firstPlan.startDate; let expiryDate = firstPlan.expiryDate;
if (currentUser.getPricingPlans(1)) {
$w(“#text156”).show();
} else
{
$w(“#text156”).hide();
I didn’t understand the line of the condition.
If you wish to show the element only for certain users try to change the condition, by using the data you got from the promise.
if(planName== "The name certain user, such as gold")
{
$w("#text156").show();
} else
$w("#text156").hide();
}
I’m having some trouble with this as well. In the user.getPricingPlans code, what do we input to show value? For example, If I had 3 plans named brand, event, and combo in that order how would where would the values go to determine which plan it is the user has?
user.getPricingPlans()
.then( (pricingPlans) => {
let firstPlan = pricingPlans[0]; ?
let planName = firstPlan.name; ?
let startDate = firstPlan.startDate; ?
let expiryDate = firstPlan.expiryDate; ?
So, given the three plan option examples, how should that code look?
And thank you for the time spent with helping us.
ok so to display elements only for X membership plan do
user.getPricingPlans()
.then( (plans) => {
plans.forEach((plan) => { let planName = plan.name; // “Plan Name”
console.log(planName); // Print out the role names of logged in user here
if (planName === “Test2”) {
$w(“#text156”).show();
$w(“#text35”).hide();
$w(“#button12”).hide();
$w(“#button16”).hide();
}
and where says “.show” just hide that element on load so will display only for planName === “Plan Name”
If I understand you correct you wish to add a condition that check what the user’s name from 3 options that you have.
First of all, the getPricingPlans() function return a promise that resolves to the pricing plans of the user that is logged in . As a result, the data that will be insert to the variables (firstName, planName…) will be the one of the current user.
Second, in order to check what is the user’s planNmae, just add a condition in the handler that compere the planName to all of the three options.
*Pay attention the “user” in the function is “wixUsers.currentUser”,so unless you create a variable “User” the function should be:
import wixUsers from 'wix-users';
wixUsers.currentUser.getPricingPlans()
.then( (pricingPlans) => {
let firstPlan = pricingPlans[0]; ?
let planName = firstPlan.name; ?
let startDate = firstPlan.startDate; ?
let expiryDate = firstPlan.expiryDate; ?
if("add the condition")
{
}
});
For any questions, pleas open a new ticket and we will be glad to help you.
Best,
Sapir