Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter kerryman

    (@kerryman)

    Yep, sorry, my mistake. Thanks for the quick correction Perry, I’ll check your add-ons also.

    Here’s a very quick custom function you can call from a template file to output the opening details for today:

    /**
     * todays_hours - Returns the a string with the opening hour details for today. Plugin wp-opening-hours required
     */
    function todays_hours () {
    	global $wp_opening_hours;
    
    	if (!is_object($wp_opening_hours))	$wp_opening_hours	= new OpeningHours;
    
    	$today		= strtolower( date('l', current_time('timestamp')) );
    
    	/* Check for Holidays */
    	foreach ((array) $wp_opening_hours->holidays as $holiday)
    		if ($holiday->isRunning())
    			return 'Store closed for '.$holiday->data['name'].'<br />'.'Reopens '.$holiday->data['end'];
    
    	/* Check for Special Openings */
    	foreach ((array) $wp_opening_hours->specialOpenings as $specialOpening) :
    		if ( $specialOpening->isToday() ) :
    			return 'Store hours today<br/>'.$specialOpening->data['name'].': '.date("g:i a", $specialOpening->start_ts).' - '.date("g:i a", $specialOpening->end_ts);
    		endif;
    	endforeach;
    
    	/* Check for regular Opening Periods */
    	foreach ((array) $wp_opening_hours->$today as $period)
    		if ($period->isRunning())
    			return 'Store hours today<br/>'.date("g:i a", $period->start_ts).' - '.date("g:i a", $period->end_ts);
    
    	return 'Store hours today<br/>'.date("g:i a", $period->start_ts).' - '.date("g:i a", $period->end_ts);
    }
Viewing 2 replies - 1 through 2 (of 2 total)