Elements show only for Paid Plans

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();

Some help?

Hi Raul,

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();
}

Best,
Sapir

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”

Hi,

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

Hi,

Determine the element to be “Hidden on load” and present it only if the condition is true it’s also a good option.

Best of luck!
Sapir

Hello,
I found this code that seems suitable for what I need, but I’m a beginner, so could you explain the passages better, please?

I should make an element visible only to those who are logged in and have a plan. Not one in particular, but simply a plan.

Thanks in advance

ok

please check

import wixUsers from 'wix-users';

$w.onReady(function () {

    const user = wixUsers.currentUser;
    let userId = user.id; // "r5cme-6fem-485j-djre-4844c49"
    let isLoggedIn = user.loggedIn; // true

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

        if (planName === "test plan"){
            $w('#sendButton').show();
            $w('#updateText').hide();
        }else{
            $w('#sendButton').hide();
            $w('#updateText').show();
        }
    });
});

is not working even on publish site . live site