hi there - after a few hours of trying tonight I am struggling to integrate the code for my final result of outputting the code as
Add to Basket now for FREE Delivery to you (est.) : Fri 03rd Sep
So i assume I dont need the 'test dates' var and I can instead use the $dates but I'm missing something to link them together as below it outputs
Add to Basket now for FREE Delivery to you (est.) : (<-nothing returned)
$hols = bankHols(date('Y'));
foreach ($dates as $d) {
$ordered = new dateTime($d);
$del = deliveryDate($ordered, $hols);
}
function deliveryDate($ordered, $hols)
{
$delivery = clone $ordered;
if ($delivery->format('H:i') > '14:00') { // if it's after 2pm. treat is as the next day
$delivery->modify('+1 day');
}
if (in_array($delivery->format('w'), [0,6])) { // if it's Sat or Sun, treat it as Monday
$delivery->modify('next monday');
}
do { // add a day for delivery until the date isn't a holiday.
$delivery->modify('+1 day');
} while (in_array($delivery->format('Y-m-d'), $hols));
return $delivery;
}
function bankHols($yr)
{
// CALC PUBLIC HOLS FOR $yr
$dates = array();
$newyr = "$yr-01-01";
switch (date('w', strtotime($newyr))) {
case 6:
$newyr = "{$yr}-01-03";
break;
case 0:
$newyr = "{$yr}-01-02";
break;
}
$dates[] = $newyr;
$easter = easter_date($yr);
array_push($dates, date('Y-m-d', strtotime('-2 days', $easter)), date('Y-m-d', strtotime('+1 days', $easter)));
$mayday = (new DateTime("first monday of may $yr"))->format('Y-m-d');
$dates[] = $mayday;
$sbank = (new DateTime("last monday of may $yr"))->format('Y-m-d');
$dates[] = $sbank;
$abank = (new DateTime("last monday of august $yr"))->format('Y-m-d');
$dates[] = $abank;
$x1 = "$yr-12-25";
$x2 = "$yr-12-26";
array_push($dates, $x1, $x2);
switch (date('w', strtotime($x1))) {
case 5:
$x2 = "$yr-12-28";
break;
case 6:
$x1 = "$yr-12-27";
$x2 = "$yr-12-28";
break;
case 0:
$x1 = "$yr-12-26";
$x2 = "$yr-12-27";
break;
}
array_push($dates, $x1, $x2);
return $dates;
}
echo 'Add to Basket now for FREE Delivery to you (est.) : ' . $delivery ;