Inventory_Presser_Shortcode_Hours_Today::create_days_array_from_hours_array( array $hours_arr )

create_days_array_from_hours_array


Description Description

Translate the hours termmeta data structure into Inventory_Presser_Business_Day objects


Top ↑

Parameters Parameters

$hours_arr

(array) (Required)


Top ↑

Return Return

(array) And array of Inventory_Presser_Business_Day objects


Top ↑

Source Source

File: includes/class-shortcode-hours-today.php

	public static function create_days_array_from_hours_array( $hours_arr )
	{
		$days = array();
		$weekdays = array_keys( INVP::weekdays() );
		for( $d=0; $d<7; $d++ )
		{
			if( empty( $hours_arr[$weekdays[$d] . '_open'] )
				|| empty( $hours_arr[$weekdays[$d] . '_close'] ) )
			{
				continue;
			}

			$day = new Inventory_Presser_Business_Day();
			$day->weekday = $d+1;

			//open hour, turn "9:00 AM" into 9 and "4:00 PM" into 15
			$date_obj = self::create_date_object_from_hour_string( $hours_arr[$weekdays[$d] . '_open'] );
			if( ! $date_obj ) { continue; }

			$day->open_hour = $date_obj->format('G');
			$day->open_minute = $date_obj->format('i');

			//close hour
			$date_obj = self::create_date_object_from_hour_string( $hours_arr[$weekdays[$d] . '_close'] );
			if( ! $date_obj ) { continue; }

			$day->close_hour = $date_obj->format('G');
			$day->close_minute = $date_obj->format('i');

			array_push( $days, $day );
		}
		return $days;
	}