Hello, I need help with a code which can check the current users status whether he is an active paid plan member or not and based on that need to show/hide certain elements on the page
Hello Sunny,
perhaps this can help you…
https://www.wix.com/corvid/reference/wix-paid-plans.html#getCurrentMemberOrders
Thank you for this, however I have written this code with I am not sure if it is correct, I am a beginner in coding
$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 === true) {
$w(“#text89”).hide();
}
} );
Can you please check this and let me know whats wrong in it :), I just need to check if the user is a paid member, if yes then I can show/hide few elements on page
Hi ![]()
You can get the current user’s pricing plans by using the getPricingPlans() function, start by importing Wix Users API module to your site.
import wixUsers from 'wix-users';
let user = wixUsers.currentUser;
$w.onReady(()=> {
user.getPricingPlans().then((plans) => {
if (plans.length > 0) {
// The member has paid plan purchased
// Handle the case here by showing and
// hiding elements
} else {
// handle the case where user doesn't have
// pricing plan
}
})
})
Hope this helps~!
Ahmad
This one worked, thank you so much Ahmad for your help. Just want to know if I can check if his plan is active or not to show/hide elements?
You’re welcome ![]()
You can know if the plan is expired or not by getting the expiry date of the plan
if (plans.length > 0) {
let firstPlan = plans[0];
let today = new Date();
if (today.getTime() >= firstPlan.expiryDate.getTime()) {
// Handle the case where the plan is expired
} else {
// handle the case where the plan is NOT expired
}
}
If you ever need help, you can tag me in your post and I’ll be glad to help if I could. You can also follow me so you can get to me easily.
Ahmad