I want elements to hide/show depending on a users paid plan level. If user is not logged in or only has the free access to the site then element #text104 will just be a short line of the paragraph I want users to see. I have shared the whole page code to see if there is any conflicts across the whole code.
// API Reference: Introduction - Velo API Reference - Wix.com
// “Hello, World!” Example: Velo Learning Center
import wixUsers from ‘wix-users’ ;
import wixData from ‘wix-data’ ;
import wixLocation from ‘wix-location’ ;
$w . onReady ( () => {
if ( wixUsers . currentUser . loggedIn ) {
} else {
$w ( “#videoPlayer1” ). hide ();
$w ( “#text113” ). show ();
$w ( “#text104” ). text = $w ( “#text104” ). text . slice ( 0 , 50 );
}
} );
export function btnfavourite_click ( event ) {
// This function was added from the Properties & Events panel. To learn more, visit Velo: Working with the Properties & Events Panel | Help Center | Wix.com
// Add your code for this event here:
if ( wixUsers . currentUser . loggedIn === true ){
let $item = $w . at ( event . context );
let currentItem = $item ( “#dataset1” ). getCurrentItem (). _id ;
let favorite = $item ( “#btnfavourite” ). style . backgroundColor ;
// console.log("Choosen data record is: " + JSON.stringify(currentItem));
if ( favorite !== “red” ){
let userid = wixUsers . currentUser . id ;
let toInsert = {
“userId” : userid ,
“classId” : currentItem ,
};
wixData . insert ( “Favourite” , toInsert )
. then ( ( results ) => {
let item = results ; //see item below
console . log ( “Success” );
$item ( “#btnfavourite” ). style . backgroundColor = “red” ;
$item ( “#favMsg” ). text = “Added to favourite!” ;
$item ( “#favMsg” ). expand ();
} )
. catch ( ( err ) => {
let errorMsg = err ;
console . log ( errorMsg );
} );
} else {
wixData . query ( “Favourite” )
. eq ( “classId” , currentItem )
. eq ( “userId” , wixUsers . currentUser . id )
. find ()
. then (( result )=>{
let ID = result . items [ 0 ]. _id ;
wixData . remove ( “Favourite” , “” + ID + “” )
. then ( ( results ) => {
let item = results ; //see item below
$item ( “#btnfavourite” ). style . backgroundColor = “white” ;
$item ( “#favMsg” ). text = “Removed from favourite!” ;
$item ( “#favMsg” ). expand ();
} )
. catch ( ( err ) => {
let errorMsg = err ;
} );
})
}
} else {
let $item = $w . at ( event . context );
$item ( “#favMsg” ). text = “Please login first!” ;
$item ( “#favMsg” ). expand ();
}
}
export function text113_click ( event ) {
let $item = $w . at ( event . context );
wixLocation . to ( “https://www.triplegoddessyoga.com/plans-pricing” );
// This function was added from the Properties & Events panel. To learn more, visit Velo: Working with the Properties & Events Panel | Help Center | Wix.com
// Add your code for this event here:
}
export function repeater1_itemReady ( $item1 , itemData1 , index1 ) {
if ( wixUsers . currentUser . loggedIn ) {
wixUsers . currentUser . getPricingPlans ()
. then (( pricingPlans ) => {
if ( pricingPlans . length > 0 ){
$item1 ( “#videoPlayer1” ). show ();
$item1 ( “#text113” ). hide ();
if ( itemData1 . url !== “” ){
$item1 ( “#videoPlayer1” ). src = itemData1 . url ;
}
} else {
$item1 ( “#videoPlayer1” ). hide ();
$item1 ( “#text113” ). show ();
let paragraph = itemData1 . description ;
var shortText = paragraph . slice ( 0 , 50 );
$item1 ( “#text104” ). text = shortText + ’ …’ ;
}
let currentPlan = pricingPlans [ pricingPlans . length - 1 ];
let planName = currentPlan . name ;
// let qprice = currentPlan.price;
//let benefits = currentPlan.benefits;
//let sdate = currentPlan.startDate;
let eDate = currentPlan . expiryDate ;
});
wixData . query ( “Favourite” )
. eq ( “userId” , wixUsers . currentUser . id )
. find ()
. then ( ( results ) => {
if ( results . items . length > 0 ) {
let firstItem = results . items [ 0 ]; //see item below
results . items . forEach ( function ( item , i ){
let classid = item . classId ;
//console.log("Class=> "+classid);
$w ( “#repeater1” ). forEachItem (( $item , itemData , index ) => {
let currentText = $item ( “#classID” ). text ;
if ( currentText === classid ){
$item ( “#btnfavourite” ). style . backgroundColor = “red” ;
}
});
});
} else {
// handle case where no matching items found
}
} )
. catch ( ( err ) => {
let errorMsg = err ;
$w ( “#favMsg” ). text = “” + errorMsg + “” ;
$w ( “#favMsg” ). expand ();
} );
} else {
$item1 ( “#videoPlayer1” ). hide ();
$item1 ( “#text113” ). show ();
let paragraph = itemData1 . description ;
var shortText = paragraph . slice ( 0 , 50 );
$item1 ( “#text104” ). text = shortText + ’ …’ ;
}
}