Check if user is a logged in member then check if boolean = true on click

I’ve been working on this for two weeks and can’t figure it out! I really hope someone can help me with this.

I have a membership site using Wix Paid Plans. Anyone can sign up but they need to be an approved member to see a reviews section on a dynamic page. I’m using a boolean field (field key: aprooveMember) in a members database to indicate if a member is approved or not. The dynamic page has permissions set to everyone. I want all page visitors to have access to some of the page content. When they click on a reviews button on that page, I want to check if they’re a logged in member. If they are, I also want to check if they’re an approved member. If they’re approved, I want them to see the reviews section so they can read and post reviews. If they’re not approved, I want to trigger an “AccountUnverified” lightbox. If they’re not logged in, I want to trigger the promptLogin lightbox.

The problem I’m having with the code is, either all page visitors can click on the reviews button and see the reviews section whatever their membership status or all page visitors can click on the reviews button and get the Account Unverified lightbox whatever their membership status. The code isn’t checking both logged in status and approval status.

Here’s the current code:

I think the button is in a repeater ???

If the button is in a repeater, first of all connect the repeater to the respective dataset…
then →

#repeater1 - repeater

$w.onReady(function () {
 $w("#repeater1").onItemReady( ($item, itemData, index) => {
  if(wixUsers.currentUser.loggedIn) {
   if(itemData.aprooveMember === true) {
    $item('#Information').enable();
    $item('#reviews').disable();
    $item('#sectionInformation').collapse();
    $item('#sectionReviews').expand();
    $item('#line569').hide();
    $item('#line570').show();
   }
    else {
     wixWindow.openLightbox("AccountUnverified");
    }
  }
   else {
    wixUsers.promptLogin();
   }
  
 });
});

Hi Ajit, thank you for your help. The button isn’t in a repeater. If I removed that part of your code, would it still work?

If the button is not in a repeater try this →

let currentItem;
 $w.onReady(function () {
$w("#dataset2").onReady(()=>{
  currentItem = $w("#dataset2").getCurrentItem().aprooveMember.toLocaleString();
  });
 });
 
 //inside the export function reviews_click(event)
  if(wixUsers.currentUser.loggedIn) {
   if(currentItem === "true") {
    $w('#Information').enable();
    $w('#reviews').disable();
    $w('#sectionInformation').collapse();
    $w('#sectionReviews').expand();
    $w('#line569').hide();
    $w('#line570').show();
   } else {
     wixWindow.openLightbox("AccountUnverified");
    }
  } else {
    wixUsers.promptLogin();
   }

Thanks Ajit.

I tried your code - its partially working. When the page visitor isn’t logged in, the login lightbox is triggering correctly. When the page visitor is a logged in and approved member, I’m able to see the reviews section, which is also correct. However, if the page visitor is a logged in member but not approved yet, I’m still able to see the reviews section, which is not correct - I should get the Account Unverified lightbox.

I’d appreciate your help to see if there’s anything else we could try?

Here’s the code as it is at the moment:

//inside the export function reviews_click(event)

  if(wixUsers.currentUser.loggedIn) {
   if(currentItem === "true") {
    $w('#Information').enable();
    $w('#reviews').disable();
    $w('#sectionInformation').collapse();
    $w('#sectionReviews').expand();
    $w('#line569').hide();
    $w('#line570').show();
   } else {
     if (currentItem === "false") {
      $w('#Information').disable();
      $w('#reviews').enable();
      $w('#sectionInformation').expand();
      $w('#sectionReviews').collapse();
      $w('#line569').show();
      $w('#line570').hide();   
      wixWindow.openLightbox("AccountUnverified");
     }
    }
  } else {
    wixUsers.promptLogin();
   }

Also make sure your lightbox’s name is “AccountUnverified”

Ajit, I’m afraid this code isn’t working either :frowning: