Skip Navigation

[Résolu] Condition based on time

This support ticket is created Il y a 7 années et 10 mois. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 -
- - - - - - -

Supporter timezone: Asia/Manila (GMT+08:00)

Marqué : 

Ce sujet contient 5 réponses, a 2 voix.

Dernière mise à jour par emerson Il y a 7 années et 10 mois.

Assisté par: emerson.

Auteur
Publications
#436545

I am trying to: show the words "We're Open" between the hours of 11am and 1:59am and show "We're Closed" between the hours of 2am and 10:59am.

I visited this URL: https://toolset.com/forums/topic/is-there-a-way-to-show-html-based-on-condition-of-the-current-eastern-time/

I have created a new shortcode with the code from the link above and tried using their conditional statement but it did not work.

I also tried this:

[wpv-conditional if="( '[new_time]' gte '2:00' ) AND ( '[new_time]' lt '11:00' )"]We're Closed[/wpv-conditional]
[wpv-conditional if="( '[new_time]' gte '11:00' ) AND ( '[new_time]' lt '2:00' )"]We're Open[/wpv-conditional]
#436547

lien caché

#436908
1.jpg

Dear Donald,
Please follow these steps below to resolved this issue:

->Add this simple code to your functions.php that will handle the analyzing of time in your own preferred timezone

// Add Shortcode
function new_time( $atts ) {

	$timezone_string 	= '';
	$times				= '';
	if ( isset( $atts['tz'] ) ) {
		$tz = $atts['tz'];
		if ( ( is_string( $tz ) ) && ( !empty( $tz ) ) ) {
			$timezone_string = $tz;			
		}		
	}
	if ( !empty ( $timezone_string ) ) {
		$reset_timezone	 = date_default_timezone_get();
		date_default_timezone_set( $timezone_string );
		$minutes = date('i', time());
		$hours = date('G', time());
		
		//Pure minutes
		$minutes =intval( $minutes );
		
		//Converted to hours
		$hour_extra = $minutes/60;
		
		//Hours now
		$times = $hours + $hour_extra;
		date_default_timezone_set( $reset_timezone );		
	}
	
	return $times;


}
add_shortcode( 'new_time', 'new_time' );

->In the backend, Toolset ->Settings -> Front end content-> Third-party shortcode arguments -> register 'new_time' as shortcode. See screenshot attached.

->Now to use this shortcode in your content template code , you can use as follows:

[wpv-conditional if="( '[new_time tz="America/New_York"]' gte '2' ) AND ( '[new_time tz="America/New_York"]' lt '10.9999' )"]We're Closed[/wpv-conditional]
[wpv-conditional if="( '[new_time tz="America/New_York"]' gte '11' ) AND ( '[new_time tz="America/New_York"]' lt '13.9999' )"]We're Open[/wpv-conditional]

Explanation: Time is using 24-hour pure hours format. So if its 2am, its 2. If its 10:59 am ,its 10.999. If 1:59 pm, its 13.999.

->In the sample Content Template code, please change 'America/New_York' in the shortcode tz shortcode parameter to your own timezone string. You can get a list of timezone strings here:

lien caché

Check under TZ column.

The above solution is tested as working in our local installation. So that should work for you as well. Let me know how it goes.

Cheers,
Emerson

#436912

The closing time is actually 1:59AM not PM....would it still be 1.999?

#436913

Would this work?

			[wpv-conditional if="( '[new_time tz="America/New_York"]' gte '2' ) AND ( '[new_time tz="America/New_York"]' lt '10.9999' )"]We're Closed[/wpv-conditional]
			[wpv-conditional if="( '[new_time tz="America/New_York"]' gte '11' ) AND ( '[new_time tz="America/New_York"]' lt '24' )"]We're Open[/wpv-conditional]
       		[wpv-conditional if="( '[new_time tz="America/New_York"]' gte '0' ) AND ( '[new_time tz="America/New_York"]' lt '1.9999' )"]We're Open[/wpv-conditional]
#437052

Hi Donald,
1:59 am is something like (1+ 59/60) = 1.999. It should work, just tried it in your site its the best way to test this thing 🙂 If it does not work, please provide login credentials to your site and we are happy to check it if its not working. Let me know the page where this is outputted on front end as well as the backend. Thanks!

Cheers,
Emerson

Ce ticket est maintenant fermé. Si vous êtes un client de Toolset et que vous avez besoin d'aide, veuillez ouvrir un nouveau ticket d'assistance