Display Lightbox only on certain days

I’d like to pop-up lightbox only on Tuesdays. Can someone please help with the code. TIA

something like this…

$w.onReady( function () {

//0 = Sunday
//1 = Monday
//2 = Tuesday
//3 = Wednesday
//4 = Thursday
//5 = Friday
//6 = Saturday

var d = new Date();
var weekDay = d.getDay()

console.log(weekDay);

if (weekDay !==2){

console.log('hide active') 

//change lightbox ID as required

 $w("#lightbox1").hide(); 

}

})

almost, but not exactly (you can’t use $w(“#lightbox1”).hide(); from the page.
It should be something like:

import wixWindow from 'wix-window';
const daysToDisplay = [0, 3, 6]; // 0 is Sunday, 6 is Saturday
let today = new Date().getDay();
if (daysToDisplay.includes(today)){
    wixWindow.openLightbox("LightboxName");
}

@jonatandor35 thank you, do i put it in a hope page, lightbox page or Site?

@info26878 if you want to open the lightbox from a specific page - put it in the page code panel. If you want this lightbox to open from any page on you site - put it in the site code panel.

@jonatandor35 thanks, I tried with both Automatically display lightbox ON or OFF and the code doesn’t supersede the trigger:( so basically if the switch is ON, it always pops out, no matter what days i put in the code.

@info26878 the automatically displayed should be set to OFF.
If it doesn’t work, maybe you didn’t use the code correctly.
Can you post it here?

@jonatandor35 I basically just copied your code and just changed the lightbox name. I also tried with OnReady function like below.

$w.onReady( function () {

const daysToDisplay = [0, 3, 5]; // 0 is Sunday, 6 is Saturday
let today = new Date().getDay();
if (daysToDisplay.includes(today)){
wixWindow.openLightbox(“LBtuesday5”);
}
});

I do have import wix-window up top

I included 0 to test if it would come up today

@info26878 I don’t know your timezone (for me It’s already Monday which means day 1) but i understand It’s Sunday in your area.
Anyway, if it is Sunday,
I can’t see any problem with your code. So maybe the lightbox name is wrong(?) (it is case-sensitive)

@jonatandor35 omg i was putting lightbox ID, not the name. I just changed with the name and it works. thank you so much

@info26878 You’re welcome :slight_smile:

New to coding need a little help trying to show a lightbox from Mon-Thu using the following code:

// For full API documentation, including code examples, visit Velo API Reference - Wix.com

import wixWindow from ‘wix-window’ ;

$w.onReady( function () {

const daysToDisplay = [ 1 , 2 , 3 , 4 ]; // 0 is Sunday, 6 is Saturday
let today = new Date().getDay();
if (daysToDisplay.includes(today)) {
wixWindow.openLightbox( “Order” );
}
})

the website is www.ginaspizzeria.com, but this do not to be working, any help…

disregard my last post did not realize that you need to shut off lightbox being shown automatically

@jonatandor35 excuse me, i don’t really know how to code. what lines should i add if i want my lightbox to show from certain hour on a day until a certain hour on a different day? for example from wednsday at 20:00 until saturday at 19:00?

@asafhel

import wixWindow from 'wix-window';
const [startDay, endDay] = [3, 6];
const [startHour, endHour] = [20, 19]
const today = new Date().getDay();
const currentHour = new Date().getHours();
if(
(endDay - startDay < 0 && (today < endDay || today > startDay)) ||
(today < endDay && today > startDay) ||
(today == startDay && currentHour >= startHour) ||
(today == endDay && currentHour < endHour)
){
    wixWindow.openLightbox("LightboxName");
}

@jonatandor35 THANK YOU!