function disable_checkout_after_hours() {
// Define your opening and closing times
$opening_time = '09:00';
$closing_time = '18:00';
// Get the current time
$current_time = current_time('H:i');
// Check if the current time is outside of the operating hours
if ($current_time < $opening_time || $current_time > $closing_time) {
// Disable checkout
wc_add_notice(('Sorry, we are currently closed. Please come back during our opening hours.'), 'error');
remove_action('woocommerce_proceed_to_checkout', 'woocommerce_button_proceed_to_checkout', 20);
}
}
add_action('woocommerce_checkout_process', 'disable_checkout_after_hours');