Hi everyone!
So I’ve created a Lightbox called “Advertisements” which in itself is self explanatory. It pops up before every page visit (except important pages like ToU, About, Contact ect.).
I am interested in allowing the site viewers the ability to not see ads if they are a member. Is there a way (and how) to have members skip the process of going through a Lightbox when visiting a page?
For members to be able to skip any lightbox then in theory they should be required to log themselves in so that you can obtain their current role or price plan etc through your code.
If they log themselves in then you can get their details:
https://www.wix.com/corvid/reference/wix-users.html#onLogin
https://www.wix.com/corvid/reference/wix-users.html#currentUser
https://www.wix.com/corvid/reference/wix-users.User.html#getRoles
https://www.wix.com/corvid/reference/wix-users.User.html#getPricingPlans
Then you can simply add additional code using the hide and show options for your lightbox which is hidden on load, so if a user logs in that is a member or a certain price plan user, then the lightbox stays hidden.
Otherwise, if people don’t log themselves in, they are not a member or a certain price plan user, then you can set your code to show the lightbox instead.
https://www.wix.com/corvid/reference/$w.HiddenMixin.html
Another option would be to have the lightbox popup as you have got it and then have a seperate members area where the lightbox is not shown on.
https://support.wix.com/en/article/creating-members-only-pages-596999
Hey @givemeawhisky
Regarding the post I made a month ago, I really appreciate your help and response. I consider myself a web designer, rather than a developer and have some trouble making the code.
I want to create a site code that when a member is logged in and a Lightbox is triggered, it collapses before the member gets to see it.
I imagine the code is about 3-5 lines. Could you help me make it? I’m a college student but will pay if you charge.
P.S in the future I plan to add paid roles (plans) to site members.
Just take a look at the Users API in the Wix API reference.
https://www.wix.com/corvid/reference/wix-users.html
https://www.wix.com/corvid/reference/wix-users.User.html
Or you can do a one time only popup as shown here in this tutorial.
https://support.wix.com/en/article/corvid-tutorial-creating-a-one-time-popup
Your site code should look something like this below.
import wixUsers from 'wix-users';
import wixWindow from 'wix-window';
$w.onReady(() => {
if (wixUsers.currentUser.loggedIn) {
wixWindow.lightbox.close('Lightbox');
} else {
wixWindow.openLightbox('Lightbox');
}
});
@givemeawhisky Wow thank you!
I actually used both the link source for “one time Lightbox open” for one of my other light boxes that is an invitation to my discord server. And the code you provided to skip the advertisement Lightbox for sight members.
I can’t thank you enough for your help! You inspire me to learn Javascript.
Hi @givemeawhisky ,
I’m changing some things up and introducing a paid plan into my site. The plan is called “Membership”.
The point is, users who are members and have this plan, get to skip the Lightbox. I did some digging around wix API references and came up with this:
import wixUsers from 'wix-users';
import wixWindow from 'wix-window';
let user = wixUsers.currentUser;
user.getPricingPlans()
.then( (pricingPlans) => {
let firstPlan = pricingPlans[0];
let planName = firstPlan.name; // "Membership"
} );
$w.onReady(() => {
if (wixUsers.currentUser.planName.Membership) {
wixWindow.lightbox.close('Advertisement');
} else {
wixWindow.openLightbox('Advertisement');
}
});
Could you tell me if this looks right? Any corrections I need to do? I would really appreciate some help in this!
Warm regards,
Dany.
Try something like below, however I have just edited your code above, so you will no doubt need to check to see if it all matches up and that there are matching pairs of curly brackets and parentheses - in other words equal numbers of open { and close } and open ( and close ).
import wixUsers from 'wix-users';
import wixWindow from 'wix-window';
$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; // "Membership"
if (planName === "Membership") {
wixWindow.lightbox.close('Advertisement');
}
else {
wixWindow.openLightbox('Advertisement');
}
});
});
@givemeawhisky So I inserted the edited code into Wix and at first glance it gave me no errors. Then I went to test it. Users who were logged in (but not have a paid membership plan) did receive the Lightbox pop-up (I want this). I am not sure if users with the paid plan get the Lightbox pop-up, haven’t tested it yet.
However, Users who were not logged in, also didn’t receive the Lightbox pop up which I was surprised by. So I edited the code a bit and did a few rearrangements, I was successful in having non-logged in users receive the Lightbox once more, however now logged in users who have NOT paid for a membership plan don’t receive the pop-up (they should, just as non-logged in users).
Goal:
- users who are not a paid member get Lightbox pop-up
- users who are logged in, and a member (paid plan) have Lightbox closed.
- clean the code as much as possible.
What am I missing? Is there unnecessary repetition or collision?
Current Code:
import wixUsers from 'wix-users';
import wixWindow from 'wix-window';
$w.onReady(function () {
let user = wixUsers.currentUser;
let userId = user.id;
let isLoggedIn = user.loggedIn;
if (isLoggedIn) {
wixWindow.lightbox.close('Advertisement');
} else {
wixWindow.openLightbox('Advertisement');
}
user.getPricingPlans()
.then( (pricingPlans) => {
let firstPlan = pricingPlans[0];
let planName = firstPlan.name; // "Membership"
$w.onReady(() => {
if (wixUsers.currentUser.planName.Membership) {
wixWindow.lightbox.close('Advertisement');
} else {
wixWindow.openLightbox('Advertisement');
}
});
});
});
You can’t have multiple onReady functions in your code. Plus, you only want the lightbox not to show to paid members only.
So try something like below and take out these two lines.
let userId = user.id;
let isLoggedIn = user.loggedIn;
So now it should only be.
import wixUsers from 'wix-users';
import wixWindow from 'wix-window';
$w.onReady(function () {
let user = wixUsers.currentUser;
user.getPricingPlans()
.then( (pricingPlans) => {
let firstPlan = pricingPlans[0];
let planName = firstPlan.name; // "Membership"
if (planName === "Membership") {
wixWindow.lightbox.close('Advertisement');
}
else {
wixWindow.openLightbox('Advertisement');
}
});
});
The APIs in wix-users are only partially functional when previewing your site. View a published version of your site to see their complete functionality.
The APIs in wix-users can only be used once the page has loaded. Therefore, you must use them in code that is contained in or is called from the onReady() event handler or any element event handler.
Hey @givemeawhisky , Thanks for your help by the way. I updated the code two weeks ago and then went traveling so I didn’t get the chance to test it or get into it.
As far as I see now, logged in users who have not purchased a membership plan get the Lightbox pop up, and users with the plan don’t. This is what I’m looking for and it functions, thanks once more. However an old problem still occurs. Users who are not logged in also don’t get the Lightbox pop up.
The idea is, if a user does not have a membership plan, then they get the Lightbox. But it doesn’t seem to trigger that for non-logged in users.
How can I make the code communicate with wix, so that it understands that the non-logged in user doesn’t have a membership plan, and so that they also get the Lightbox pop up?
I know I am taking up so much of your time and Im sorry for being frustrating. I can offer payment for your work if you request.
@givemeawhisky Hey, it’s been a while since we’ve last spoke of the problem. Any chance you came by something a solution that could help me? Cheers.
@deleteduser Thank you so much for your time and attention, I will check this tomorrow morning
May I ask how you found this forum, its pretty old haha.
@deleteduser Ah okay, I was just surprised by your response, which is much appreciated btw. Hey so disappointing news again, the Lightbox still doesn’t trigger. This time the Lightbox doesn’t open under any condition. Whether the user is logged in or not, or a paid member.
I also haven’t really given much thought into the membership part of the code, I just sort of looked at the API and copied stuff down, maybe that’s messing stuff up? For instance, I don’t know if the plan “membership” is even my first plan, because I have other archived inactive plans (they can’t be deleted). Do you think this could affect the other user roles to not be working? I personally doubt it, as before at least logged in users got the pop up. Maybe it’s just that the code can’t tell who is who.
let firstPlan = pricingPlans[0];
let planName = firstPlan.name; // "Membership"
@deleteduser Hey sorry for not replying earlier, I think Wix is having problems again because Im not getting any emails, and my profile page is messed up, nothing loads.
I was just thinking about what you proposed, I replaced wixUsers.currentUser with !user. To my misfortune it didn’t do any good. However… I was spending like 2 hours comparing all the previous versions of this code and I came up with a combination of the old and new. As you might know (I may be confusing when I explain things), the goal is to show the advertising lightbox to anyone who is not a paid member (doesnt have a plan). So I came up with the code below.
What it does, is show the Lightbox to logged in users, and non-logged in users. I am not yet sure if paid members have the lightbox closed as I have to check it, but lets cross our fingers it does. Thank you for your great help so far ![:slight_smile: :slight_smile:](/images/emoji/google_classic/slight_smile.png?v=12)
import wixUsers from 'wix-users';
import wixWindow from 'wix-window';
$w.onReady(function () {
let user = wixUsers.currentUser;
let isLoggedIn = user.loggedIn;
if (isLoggedIn) {
wixWindow.openLightbox('Advertisement');
} else {
wixWindow.openLightbox('Advertisement');
}
user.getPricingPlans()
.then( (pricingPlans) => {
let firstPlan = pricingPlans[0];
let planName = firstPlan.name; // "Membership"
if (planName === "Membership") {
wixWindow.lightbox.close('Advertisement');
}
});
});