Created
July 13, 2024 01:23
-
-
Save rajeshsingh520/e2db10de88de0009ea1e5504157073bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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