How to disable WooCommerce checkout on specific date or weekday

You probably know that WooCommerce is one of the most popular ecommerce platforms around the world. Since it’s relatively easy to set up, there are various businesses that use it not only for selling products.

For example, one of my clients uses WooCommerce for food reservation in a small Sushi restaurant. And there are days when restaurant does not work. For example – on Mondays, first week after New year, etc. So he asked me to build a function to disable checkout on specific dates or weekdays. Today I’ll show you how to add this function to your WooCommerce website too.

Just before starting we need to do a small thing – go to your store and create a page with a message telling something like “Sorry, we’re not working ath the moment, come back tomorrow”. You’ll need a link to this page a bit later.

How to disable WooCommerce checkout on specific weekday

Here’s an example how to disable checkout on Monday.

Go to Appearance >> Theme File Editor, or Tools >> Theme File Editor, and open file function.php on the right side of the screen.

Once you’re there, add this code to the end of the functions.php file:

add_action( 'woocommerce_check_cart_items', 'woocommerce_check_cart_quantities' );
function woocommerce_check_cart_quantities() {
    if (date('D') == 'Mon') {
       wp_redirect('https://yourwebsite.com/come-back-later');
    }
}

What this functions does? It basically interrupts one of the checkout functions. If weekday is Monday, it automatically redirects customer to the page you created before – the one which tells that store does not work at the moment.

If you want to disable checkout on weekends, you can replace if (date(‘D’) == ‘Mon’) { with:

if ( (date('D') == 'Sat') || (date('D') == 'Sun') ) {

You can use Mon, Tue, Wed, Thu, Fri, Sat and Sun for weekdays in the function.

How to disable WooCommerce checkout on a specific date or daterange

To disable checkout in WooCommerce on specific dates, we’ll use the same function as before, just with some changes.

Go to Appearance >> Theme File Editor, or Tools >> Theme File Editor, and open file function.php on the right side of the screen. Then add this code to the end of the functions.php file, same as before:

add_action( 'woocommerce_check_cart_items', 'woocommerce_check_cart_quantities' );
function woocommerce_check_cart_quantities() {
    $date_now = date("Y-m-d");      // get today's date
    if ( $date_now == '2022-12-25') {    // date format year-month-day
        wp_redirect('https://yourwebsite.com/come-back-later');
    }
}

Once you’ll save changes customer will automatically be redirected to your specified URL on that date.

If you want to disable checkout in your WooCommerce store for more than one day you can use the same function for the entire daterange. Just replace if ( $date_now == ‘2022-12-25’) { with this line:

if ( ( $date_now > '2022-12-24') && ($date_now < '2023-01-02') ) {

In this specific example checkout would be disabled from 2022-12-25 to 2023-01-01.