WooCommerce: Holiday/Pause/Closed Mode

A WooCommerce freelance client had a special request for their online store. And sometimes, just like physical stores, your WooCommerce website need to go on holiday! This means disabling cart, checkout and show a little notice on every WooCommerce page.

WooCommerce Holiday/Pause Mode: disable cart, checkout, add to cart
WooCommerce Holiday/Pause Mode: disable cart, checkout, add to cart

PHP Snippet: WooCommerce Holiday/Pause Mode

A little note: of course this snippet can be controlled by an “ON/OFF” switch in the WooCommerce settings. To make this snippet easier, however, I haven’t provided this additional functionality.


/**
 * @snippet       WooCommerce Holiday/Pause Mode
 * @how-to        Watch tutorial @ https://businessbloomer.com/?p=19055
 * @sourcecode    https://businessbloomer.com/?p=20862
 * @author        Rodolfo Melogli
 * @testedwith    WooCommerce 3.5.1
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

// Trigger Holiday Mode

add_action ('init', 'bbloomer_woocommerce_holiday_mode');


// Disable Cart, Checkout, Add Cart

function bbloomer_woocommerce_holiday_mode() {
   remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
   remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
   remove_action( 'woocommerce_proceed_to_checkout', 'woocommerce_button_proceed_to_checkout', 20 );
   remove_action( 'woocommerce_checkout_order_review', 'woocommerce_checkout_payment', 20 );
   add_action( 'woocommerce_before_main_content', 'bbloomer_wc_shop_disabled', 5 );
   add_action( 'woocommerce_before_cart', 'bbloomer_wc_shop_disabled', 5 );
   add_action( 'woocommerce_before_checkout_form', 'bbloomer_wc_shop_disabled', 5 );
}


// Show Holiday Notice

function bbloomer_wc_shop_disabled() {
        wc_print_notice( 'Our Online Shop is Closed Today :)', 'error');
} 

Where to add this code?

You can place PHP snippets at the bottom of your child theme functions.php file (before "?>" if you have it). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such delicate files - if you need more guidance, please take a look at my free WooCommerce Customization video tutorial.

Does this snippet still work?

Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7.

If you think this code saved you time & money, please join other Business Bloomer supporters and avail of 365 days of WooCommerce benefits. Thank you in advance :)

Need Help with WooCommerce?

Check out these free videos, tutorials and tips!

  • how-to-edit-woocommerce-with-php-snippets
  • woocommerce-hooks-add_action-list-visual
  • woocommerce-customize-single-product-page-PHP
  • woocommerce-customize-shop-page-PHP
  • woocommerce-advanced-customization
  • how-to-edit-woocommerce-cart
  • woocommerce-customize-checkout-page-PHP
  • woocommerce-email-customization
  • woocommerce-conditional-logic

Rodolfo Melogli

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as a WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza.

37 thoughts on “WooCommerce: Holiday/Pause/Closed Mode

  1. Worked like a charm, thank you!

    In combination with a cookie-enabled popup (“sold separately” ๐Ÿ™‚ ), this is exactly what the doctor ordered!

    Appreciate you sharing this useful code. Thanks!

    1. Great!

  2. Hello Rodolfo,
    Thx for this snippet.
    You speak about ON/OFF functionality, do you have Tips to add this ?
    Thx.

    1. Not at the moment, sorry!

  3. worked perfectly on the theme ‘wplms’

    1. Great!

  4. Many thanks for this code snippet, I used the above code today on a Divi themed site with php7, all worked well.

    I have copied the entire code to my blog as reference for myself, so I know how to open the shop on my return as well as linking back to this page with credit to yourself. (if that is ok).

    1. Cool ๐Ÿ™‚ Happy new year!

  5. 1st thx a lot Rodolfo! ppl plz knows someone (sure u know Rodolfo, plz answer my friend) how to do it for different days and hours? example close th store on sundays or at middays………….. thx a lot

    1. Hey there, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ~R

  6. Is there an Option, to make the Snippet Code like this, that the add to cart is disable, only on Tuesday.
    Monday, Wednesday…Sunday the add to cart is enable from 17 o clock until 2 pm?
    is this possible, i search a plugin like this, since 5 Hours… I hope you can help me..

    1. Hey Mergim, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  7. Hi, great work, I was just wondering how it is detected the opening/closing hours etc, I am using the Business Hours plugin to set those, are these automatically detected? many Thanks

    1. Hey Paul, thanks for your message! No, my snippet is generic and only compatible with default WooCommerce. Sorry ๐Ÿ™‚

  8. Wonderful, thank you! I’d always rather add a snippet than download yet another plugin if I can go that way. Good job.

  9. Thank you! Just added it – was exactly what I needed.

    1. Cheers Cathy – happy holidays then ๐Ÿ™‚

  10. Thank you for this example. I just added it to my functions.php file and it seems to be working correctly. There is a nice looking plugin in the WordPress repository as well for putting Woo shops on Vacation, however at least one order somehow slipped through that plugin.

    1. Excellent, thank you Tim ๐Ÿ™‚

  11. Thank you so much. The code worked perfectly. How can I operate the button โ€œON/OFFโ€ switch in the WooCommerce settings.

    1. Thaigon, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  12. This code was really helpful, nice easy way to ensure the shop is closed while I transfer the site over to another server and setup SSL.

    Thank you!

    1. Cheers Charlotte ๐Ÿ™‚

  13. Hi, it worked pefectly! Thanks a lot, solves a big problem for me.

  14. Just wanted to say “Thanks all”

    That was awesome and so helpful when moving servers to put the old site on ice ๐Ÿ˜‰

    1. Great, thank you Thomaz!

  15. Hi
    Thrilled to find this – set it up to test it out and it looks like it works great ! I am presently setting up a development site to replace my 14 year old oscommerce store. I am wondering if perhaps it wouldnt be beneficial or possible to allow customers to add items to their cart, but just not checkout.
    I had something similar on my oscommerce store that worked this way, the benefit it that once you return from vacation, you can view what people wanted to buy while you were away, contact them advising the store was now open and perhaps regain the sale. Would love to hear your thoughts on this.

    1. Hey Deb, thanks for your comment! You could disable automatic payments, and enable “COD” (rename it to something else). In that way the user completes the checkout but doesn’t pay, and when you come back from the Order page you can invoice them ๐Ÿ™‚

    2. I think I found my solution – if I comment out the first 2 remove actions in your code –

      // remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
      // remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
      

      then customers are able to add to cart, but the checkout is still disabled. This seems to work well and it will then create an abandoned cart, and I can contact them on return from vacation. I cant see that it is negatively affecting anything else…. your thoughts ?

    3. Yes, that looks perfect ๐Ÿ™‚

  16. Rodolfo,
    How is this different than the Woocommerce site-wide store notice? I’m trying to use that to show a sale throughout the month and it is actually covering up my navigation bar so am wondering if your suggestion might meet my need and NOT cover it up.

    1. Hey Liz, thanks for your comment! Well, yes you can re-adapt this and it will show a notice inside the content, not above the page. The Woo site-wide store notice might work too, but you’ll need to play with custom CSS and z-index to decide which one should stay on top. Let me know ๐Ÿ™‚

  17. Thank you for this wonderful snippet, it works perfectly!!

    1. And thank you for your wonderful feedback ๐Ÿ™‚

  18. […] Den Onlineshop an Feier- und Ferientagen dicht machen? Nicht wirklich kundenfreundlich. Wer es trotzdem braucht: Hier. […]

Questions? Feedback? Support? Leave your Comment Now!
_____

If you are writing code, please wrap it between: [php]code_here[/php]. Failure to complying with this (as well as going off topic) will result in comment deletion. You should expect a reply in about a week - this is a popular blog but I need to get paid work done first. Please consider joining #BloomerArmada to ask me 1-to-1 WooCommerce questions. Thank you :)

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.