# Accept Orders Only During Opening Hours

> Disables checkout outside your opening hours and shows a notice with the time you open again. Ideal for restaurants and local delivery.

- Type: PHP
- Runs: Run everywhere
- Category: [WooCommerce](https://wpide.com/library/category/woocommerce/)
- Requires: WooCommerce
- Tags: woocommerce, checkout, hours, restaurant
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/woo-store-opening-hours/

## Code

```php
$wpide_opening_hours = array(
    // Day number => array( open, close ) in 24h format.
    1 => array( '09:00', '21:00' ),
    2 => array( '09:00', '21:00' ),
    3 => array( '09:00', '21:00' ),
    4 => array( '09:00', '21:00' ),
    5 => array( '09:00', '22:00' ),
    6 => array( '10:00', '22:00' ),
);

$wpide_store_is_open = function () use ( $wpide_opening_hours ) {
    $now = new DateTime( 'now', wp_timezone() );
    $day = (int) $now->format( 'N' );

    if ( empty( $wpide_opening_hours[ $day ] ) ) {
        return false;
    }

    $time = $now->format( 'H:i' );

    return $time >= $wpide_opening_hours[ $day ][0] && $time < $wpide_opening_hours[ $day ][1];
};

add_action( 'woocommerce_check_cart_items', function () use ( $wpide_store_is_open ) {
    if ( ! $wpide_store_is_open() ) {
        wc_add_notice( 'We are closed right now. You can browse and fill your cart, and place your order during our opening hours.', 'error' );
    }
} );

add_action( 'woocommerce_checkout_process', function () use ( $wpide_store_is_open ) {
    if ( ! $wpide_store_is_open() ) {
        wc_add_notice( 'Sorry, we are not taking orders at the moment.', 'error' );
    }
} );
```

## Notes

Times use the site timezone from Settings > General. Set $open and $close per weekday (1 = Monday ... 7 = Sunday); leave a day out to close all day.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Accept Orders Only During Opening Hours" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
