php - Automatically change order status during specific hours and days in Woocommerce

one text

Solution:

As Dave S commented Where does this code run now? As I can see your code looks fine but it can improve a little better so I revised your code a little bit.

First, you added $is_week_days and $is_friday in the same condition so you can just add day 5 to $is_week_days to check for Friday as well.

You added extra round bracet in this condition ($now_time < $end_time)

and, you can check this $status != "completed" case in your weekdays condition.

$is_week_days  = in_array( date('w'), array( 1, 2, 3, 4, 5 ) ) ? true : false; // From Monday to Friday
$start_time    = mktime( '08', '00', '00', date('m'), date('d'), date('Y') ); // 8am
$end_time      = mktime( '16', '00', '00', date('m'), date('d'), date('Y') ); // 4pm
$now_time      = time();

if ( $is_week_days && ( $now_time >= $start_time && $now_time <= $end_time ) && $status != "completed" ) {
    $order->update_status( 'completed' );
    return;
}

Source