Example #1
0
 /**
  * Loop through the opening hours and structure the data in a new array.
  *
  * @since 2.0.0
  * @return array $opening_hours The formatted opening hours
  */
 public function format_opening_hours()
 {
     $week_days = wpsl_get_weekdays();
     // Use the opening hours from the editor page or the add/edit store page.
     if (isset($_POST['wpsl_editor']['dropdown'])) {
         $store_hours = $_POST['wpsl_editor']['dropdown'];
     } else {
         if (isset($this->store_data['hours'])) {
             $store_hours = $this->store_data['hours'];
         }
     }
     foreach ($week_days as $day => $value) {
         $i = 0;
         $periods = array();
         if (isset($store_hours[$day . '_open']) && $store_hours[$day . '_open']) {
             foreach ($store_hours[$day . '_open'] as $opening_hour) {
                 $hours = $this->validate_hour($store_hours[$day . '_open'][$i]) . ',' . $this->validate_hour($store_hours[$day . '_close'][$i]);
                 $periods[] = $hours;
                 $i++;
             }
         }
         $opening_hours[$day] = $periods;
     }
     return $opening_hours;
 }
 /**
  * Create a table for the opening hours.
  * 
  * @since  2.0.0
  * @todo   add schema.org support.
  * @param  array   $hours       The opening hours
  * @param  boolean $hide_closed Hide the days where the location is closed
  * @return string  $hour_table  The opening hours sorted in a table
  */
 public function create_opening_hours_tabel($hours, $hide_closed)
 {
     $opening_days = wpsl_get_weekdays();
     // Make sure that we have actual opening hours, and not every day is empty.
     if ($this->not_always_closed($hours)) {
         $hour_table = '<table class="wpsl-opening-hours">';
         foreach ($opening_days as $index => $day) {
             $i = 0;
             $hour_count = count($hours[$index]);
             // If we need to hide days that are set to closed then skip them.
             if ($hide_closed && !$hour_count) {
                 continue;
             }
             $hour_table .= '<tr>';
             $hour_table .= '<td>' . esc_html($day) . '</td>';
             // If we have opening hours we show them, otherwise just show 'Closed'.
             if ($hour_count > 0) {
                 $hour_table .= '<td>';
                 while ($i < $hour_count) {
                     $hour = explode(',', $hours[$index][$i]);
                     $hour_table .= '<time>' . esc_html($hour[0]) . ' - ' . esc_html($hour[1]) . '</time>';
                     $i++;
                 }
                 $hour_table .= '</td>';
             } else {
                 $hour_table .= '<td>' . __('Closed', 'wpsl') . '</td>';
             }
             $hour_table .= '</tr>';
         }
         $hour_table .= '</table>';
         return $hour_table;
     }
 }