Skip to content

Instantly share code, notes, and snippets.

@rajeshsingh520
Created July 13, 2024 01:23
Show Gist options
  • Save rajeshsingh520/e2db10de88de0009ea1e5504157073bb to your computer and use it in GitHub Desktop.
Save rajeshsingh520/e2db10de88de0009ea1e5504157073bb to your computer and use it in GitHub Desktop.
add_filter('pi_dtt_date_generator', function($dates){
// Get the current date and day of the week using WordPress's current_time() function
$today = new DateTime(current_time('Y-m-d'));
$dayOfWeek = $today->format('w'); // Get the day of the week (0 = Sunday, 6 = Saturday)
$dates = []; // Initialize the dates array
if ($dayOfWeek == 6) {
// If today is Saturday, no dates should be shown
return $dates;
}
if ($dayOfWeek == 0) {
// If today is Sunday, show dates from Monday to Sunday of next week
$startDate = new DateTime(current_time('Y-m-d'));
$startDate->modify('next Monday');
$endDate = (clone $startDate)->modify('+6 days');
} else {
// If today is any other day, show dates from today until the end of this week (Sunday)
$startDate = clone $today;
$endDate = (clone $today)->modify('next Sunday');
}
// Generate dates from $startDate to $endDate
while ($startDate <= $endDate) {
$dates[] = $startDate->format('Y/m/d');
$startDate->modify('+1 day');
}
return $dates;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment