I want to show an estimated delivery time in my shop. If a customer orders before 4pm, he gets his order the next day. But if the order is on a friday or on the weekend, he gets the order on the next monday.
That all works fine. But I need to add some holidays like christmas, new year and local holidays based on a state in my country.
I found a solution to identify the fixed and flexible (like easter) holidays in my state.
But I don't know how to work with them in the current function. If an order is placed before one of these holidays I need to move the future date some days ahead.
Here's the current code (based on this code):
date_default_timezone_set( 'Europe/Berlin' );
$current_year = date('Y');
$next_year = date('Y', strtotime( $current_year." + 1 year" ));
// Holidays
$neujahr = date('d.m.Y',strtotime(date($next_year.'-01-01')));
$ostern = date('d.m.Y', easter_date($current_year));
$karfreitag = date( "l jS F", strtotime( $ostern." - 2 days" ) );
$ostermontag = date( "l jS F", strtotime( $ostern." + 1 days" ) );
$tagderarbeit = date('d.m.Y',strtotime(date('Y-05-01')));
$himmelfahrt = date( "l jS F", strtotime( $ostern." + 39 days" ) );
$pfingstmontag = date( "l jS F", strtotime( $ostern." + 50 days" ) );
$fronleichnam = date( "l jS F", strtotime( $ostern." + 60 days" ) );
$einheit = date('d.m.Y',strtotime(date('Y-10-03')));
$allerheiligen = date('d.m.Y',strtotime(date('Y-11-01')));
$weihnachten1 = date('d.m.Y',strtotime(date('Y-12-25')));
$weihnachten2 = date('d.m.Y',strtotime(date('Y-12-26')));
// if FRI/SAT/SUN delivery will be MON
if ( date( 'N' ) >= 5 ) {
$del_day = date( "l jS F", strtotime( "next monday" ) );
$order_by = "Monday";
}
// if MON/THU after 4PM delivery will be TOMORROW
elseif ( date( 'H' ) >= 16 ) {
$del_day = date( "l jS F", strtotime( "tomorrow" ) );
$order_by = "tomorrow";
}
// if MON/THU before 4PM delivery will be TODAY
else {
$del_day = date( "l jS F", strtotime( "today" ) );
$order_by = "today";
}
$html = "<br><div class='woocommerce-message' style='clear:both'>Order by 4PM {$order_by} for delivery on {$del_day}</div>";
echo $html;