• Resolved spikerrbg

    (@spikerrbg)


    how to make in real time to show store its open or close.
    Example from 10:00-16:00 its work to show green color and after workday finish to show red color.
    Good day.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Denra.com

    (@denra)

    Hi @spikerrbg,

    The plugin does not support this functionality. However here is a custom code for you to achieve what you need. Place the following in the functions.php of your child theme:

    function wpdts_opened_closed( $atts, $content ='' ) {
        // open time
        $hm_open = '10:00';
        // close time
        $hm_close = '16:00';
        // time format (default or custom)
        $format = get_option( 'time_format' );
        // current timestamp for hour and minute
        $ts_now = strtotime( date ('G:i', current_time( 'timestamp', false ) ) );
        // open timestamp for hour and minute
        $ts_open = strtotime( date( $hm_open, $ts_now ) );  
        // close timestamp for hour and minute
        $ts_close = strtotime( date( $hm_close, $ts_now ) ); 
        // check if work time
        if ( $ts_now < $ts_open || $ts_now > $ts_close ) {
            $color = '#800'; // closed color
        }
        else {
            $color = '#080'; // opened color
        }
        return '<span style="color:' . $color. ';">' . date( $format, $ts_now ) . '</span>';
    }
    add_shortcode( 'wpdts-colored-time', 'wpdts_opened_closed' );

    Then you can use the shortcode [wpdts-colored-time] to show the current time in the default WordPress format.

    You can modify the open and close time, the display format, color codes, or other part of the code as you wish.

    Please let us know if that worked for you.

    PS: You do not need the WPDTS plugin installed to use this function but you can keep the plugin installed if you need it for other purposes.

    Plugin Author Denra.com

    (@denra)

    Addition: If you want to show the words ‘opened’ or ‘closed’ instead of current time, you can change the above code as follows:

    function wpdts_colored_opened_closed( $atts, $content ='' ) {
        // open time
        $hm_open = '10:00';
        // close time
        $hm_close = '16:00';
        // time format (default or custom)
        $format = get_option( 'time_format' );
        // current timestamp for hour and minute
        $ts_now = strtotime( date ('G:i', current_time( 'timestamp', false ) ) );
        // open timestamp for hour and minute
        $ts_open = strtotime( date( $hm_open, $ts_now ) );  
        // close timestamp for hour and minute
        $ts_close = strtotime( date( $hm_close, $ts_now ) ); 
        // check if work time
        if ( $ts_now < $ts_open || $ts_now > $ts_close ) {
            $text = '<span style="color:#800;">closed</span>';
        }
        else {
            $text = '<span style="color:#080;">opened</span>';
        }
        return $text;
    }
    add_shortcode( 'wpdts-opened-closed', 'wpdts_colored_opened_closed' );

    and then use:

    [wpdts-opened-closed]

    Thread Starter spikerrbg

    (@spikerrbg)

    Hello mate.
    Im wanna thanks so mutch. Its work.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘work time open or close’ is closed to new replies.