Skip to content

Instantly share code, notes, and snippets.

@hedqvist
Last active April 18, 2023 09:15
Show Gist options
  • Save hedqvist/fedc93f51a18b65fdf7e29b550749868 to your computer and use it in GitHub Desktop.
Save hedqvist/fedc93f51a18b65fdf7e29b550749868 to your computer and use it in GitHub Desktop.
Gordon - Blacklist Saturday, Sunday & Mondays
<?php
/**
* @snippet WooCommerce - Blacklist dates for Gordon Delivery
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 4.9.0
*/
function redlight_gordon_blacklist_certain_days( $date_array ) {
//På söndagar efter 23, hantera det som midnatt
if(date('H') >= 23 && date('H') < 24 && date('N') == 7) {
$lastSunday = date('Y-m-d',strtotime('last sunday',strtotime('tomorrow')));
}else{
$lastSunday = date('Y-m-d',strtotime('last sunday'));
}
$start = new DateTime($lastSunday);
$end = new DateTime(); // Current date time
for ($i = 1; $i <= 20; $i++) {
$date = new DateTime(date('Y-m-d', strtotime("+$i day")));
$diff = $start->diff($date);
if ($diff->d > 17 ) {
$date_array[] = $date->format('Y-m-d');
}
}
return $date_array;
}
add_filter('redlight_gd_delivery_window_blacklist', 'redlight_gordon_blacklist_certain_days', 10 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment