So the answer was simpler than I thought. Well, I'm still not 100% sure that the first part is absolutely correct, but it should be (according to my logic).
First create an array of dates this week (given this answer )
$today = time(); if (date('D', $today) === 'Mon') { $timestamp = strtotime('this Monday'); } else{ $timestamp = strtotime('last Monday'); } $days = array(); $dates = array(); for ($i = 0; $i < 7; $i++) { $days[] = strftime('%A <br /> %d %b %Y', $timestamp); $dates[] = strftime('%d %b %Y', $timestamp); $timestamp = strtotime('+1 day', $timestamp); }
The first if else loop was to check if Monday is set today so that you fill the array next Sunday (in the same week). If it's Tuesday, then the timestamp reference is the last Monday.
And then just do foreach
$return .= '<table class="reservation_time_table"> <tr><th>'.esc_html__('Hours', 'time_reservation').'</th>'; foreach ($days as $day => $day_value) { $return .= '<th>'.$day_value.'</th>'; } $return .= '</tr>'; for ($hour=8; $hour < 23 ; $hour++) { $return .= '<tr>'; $return .= '<th>'.$hour.':00</th>'; foreach ($dates as $date => $date_value) { $full_hour = $hour. ':00'; $return .= '<td data-time="'.strtotime($date_value. ' ' .$full_hour).'"></td>'; } $return .= '</tr>'; } $return .= '</table>';
And my dates over time are in data-time , mature to capture jquery: D
source share