Hide/show elements based on a user paid plans (three plans Prestige, premium and free plan)

I have three membership plans and depending on the membership level with users logging in I want to hide some elements in page. below is the code I have so far any help would be appreciated.

Thanks!

// Velo API Reference: Velo Docs

import wixUsers from ‘wix-users’;
import wixData from ‘wix-data’;

const user = wixUsers.currentUser;

user.getPricingPlans().then(plans => {
const prestige = ‘Prestige’;
const premium = ‘Premium’;

//Define an object to store plan status
const userPlans = {
    prestige: false,
    premium: false
};

// Log the full plans array to see all active plans for the user
console.log("User's active plans:", plans);

// Loop through each plan to log individual details
plans.forEach(plan => {
    console.log(`Plan Name: ${plan.name}`);
    // Log additional details as needed
});

// Update userPlans based on the user's active plans
for (const plan of plans) {
    if (plan.name.toLowerCase() === prestige.toLowerCase()) {
        userPlans.premium = true;
    } else if (plan.name.toLowerCase() === premium.toLowerCase()) {
        userPlans.premium = true;
    }
}

//check user plans and show the suitable elements
if (userPlans.prestige) {
    //show the elements meant for paid members
    $w('#serviceListWidget1').hide();
}
if (userPlans.premium) {
    //show the content for members who have the free plan
    $w('#bookingsList1').hide();
}

})

Hi, GolfPark_VA !!

It seems that deprecated APIs are being used overall, so it might be better to use the newer APIs. Is this code something you wrote yourself? :thinking: