Skip Navigation

[Gelöst] View based on date.

This support ticket is created vor 7 Jahre, 4 Monate. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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

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

This topic contains 5 Antworten, has 2 Stimmen.

Last updated by Luo Yang vor 7 Jahre, 4 Monate.

Assisted by: Luo Yang.

Author
Artikel
#469847

I was the one who submitted this ticket: https://toolset.com/forums/topic/condition-based-on-time/ and it worked out great.

Now I am trying to make it so that on December 25 (for example) it says we're closed bypassing the other conditionals that are present.

This is what I have in my view now:

[wpv-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
		<wpv-loop>
			[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]
		</wpv-loop>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"][/wpml-string]</strong>
	[/wpv-no-items-found]
[wpv-layout-end]
#470179

Dear donald,

It needs custom codes, for example, you can try this:
1) add below codes into your theme/functions.php:

function new_time_2( $atts ) {
 
    $timezone_string    = '';
    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 );
		$res = date('F j');
        date_default_timezone_set( $reset_timezone );       
    }
     
    return $res;
 
 
}
add_shortcode( 'new_time_2', 'new_time_2' );

2) Dashboard-> Toolset-> Settings-> Front-end Content
option "Third-party shortcode arguments" add the shortcode name "new_time_2",

3) Use above shortcode in your content like this:
[wpv-conditional if="('[new_time_2 tz="America/New_York"]' eq 'December 22' ) " ]We're Open[/wpv-conditional]

#470273

That worked great but can it override the other conditionals so that it doesn't show "We're Open and We're Closed" during the normal operating hours?

#470448

You can try this:
1) Create a content template "normal-days", with below codes:

[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]

2) Modify the shortcode in Views loops as below:

[wpv-conditional if="('[new_time_2 tz="America/New_York"]' eq 'December 22' ) " debug="true"]We're Open[/wpv-conditional]
[wpv-conditional if="('[new_time_2 tz="America/New_York"]' eq 'December 22' ) " evaluate="false"  debug="true"][wpv-post-body view_template="normal-days"][/wpv-conditional]

More help:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-conditional
evaluate (opt): true | false
It can be set to true or false and controls whether we want the condition to be met or not. The default value is true.

#470557

I had this showing where it was suppose to show something else.

#470847

I just test it in my localhost, it works fine, if you more assistance for it, please duplicate same problem in a test site, and fill below private detail box with login details, also point out the problem page URL, and where I can edit you codes, I need a live website to test and debug. thanks

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.