Please let me know in the comments if everything went 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.
Check out these free video tutorials. You can learn how to customize WooCommerce without unnecessary plugins, how to properly configure the WooCommerce plugin settings and even how to master WooCommerce troubleshooting in case of a bug!
Business Bloomer Founder
Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent 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.
78 thoughts on “WooCommerce: Enable Holiday / Pause / Vacation Mode”
Works great with but with one minor exception, virtual products can still be added to the cart. The cart is disabled as expected. Using YITH WooCommerce Gift Cards plugin to create the virtual product. Woo 6.0.0, WP 5.8.2
Thanks for that Neal! Virtual product (default ones) use the same add to cart button as other product types, so this will hide buttons for all standard products. If YITH uses its own buttons that I don’t know, in case you’ll need custom code for that
Is it possible to apply this code to all the products but keep active 4 or 5?
I wonder if I need to apply some kind of conditional like if($post->ID != 671),
Hi Renzo, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
we can use this instead of the above
If that works, then of course!
This is perfect! Thank you. Love your code snippets 😉
Hi Rodolfo, this is just what I need.
I run a store with some subscription products – will this code stop those renewals from processing during the “closed” period?
Great. Nope, that’s a different thing. Sorry
How can I use this code to open and close my woocommerce store in special hours? i.e open in 8:00 A.M and close in 11:00 P.M
Hi Mohammad, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
wow its working….. can it working automatically i.e. notice will appear automatically every Friday and disappear Sunday???
Hi Umar, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Hi, On my site it is not showing Holiday Notice, others works fine,.
Using WP Version 5.4.2 and WooCommerce Version 4.3.0
Ouch. Test with a different theme please?
Great little code snippet. Works perfect with woocommerce 4.2.2 and the sober theme. Thanks a lot
Works great with Woocommerce!!! Except it still allows the person to the “shop” url which displays all the products and allows them to add to cart.
Not sure I understand 😐
Nice little snippet! I was wondering what to do as this is the first time any of my clients have wanted to turn off the ability to purchase.
Worked like a charm with Woocommerce 3.8.1, WP 5.3.2 and Beaver Builder.
Hi Rodolfo. Colin here in sunny Scotland. Tested this snippet in my functions file on wordpress 5.4
It works fine
how can use this snippet only for wholesale role?
Wholesale role is: “wholesale_customer”
Hi Mimmo, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
very neat solution
Hi, this has been working awesome until I updated to Woocommerce Version 3.8.1, is there any way to have it mended for this version? A great solution while being able to keep the shop running!
It should still work
Unfortunately it doesn’t work with using Divi using their modules to create the page.
Pity. Divi heavily overrides Woo as long as I know, so some hooks might be different
Is there a way to schedule this code? For example, if I want it to run on 24 December – 5 January.
Hi Zuleika, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
It works! Thanks so much. The only improvements I’d like are:-
1. To center the message “Our Online Shop is Closed Today :)”
2. Can I access the version which can be controlled by an “ON/OFF” switch in the WooCommerce settings? Otherwise, to keep it simple but to disable this, should I just comment out the final lines of code:-
2) Just comment out the line that triggers that function, not the function.
Hope this helps!
Hello this code still work.
Can this snippet be translated? I use WMPL but can’t find it with the string translation tool.
Hey Olele, thanks for your comment! In order to make a string translatable you have to wrap it in a __() function: https://codex.wordpress.org/I18n_for_WordPress_Developers#Translatable_strings – hope this helps 🙂
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!
Thx for this snippet.
You speak about ON/OFF functionality, do you have Tips to add this ?
Not at the moment, sorry!
I am very newbie WP developer.
I didn’t know how to add the ON/OFF functionallity but I put all your snippet code in a separate plugin with the following description:
> Description: Activating this plugin will disable SHOP or Purchases.
and I use “Activate/Deactivate” from the “WordPress -> Plugins” tab.
If it’s stupid, but it works, then it isn’t stupid, right?
Interestingly enough the Shop and Basket can still be visited, but you cannot “proceed to checkout” and “wc_print_notice” is displayed.
worked perfectly on the theme ‘wplms’
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).
Cool 🙂 Happy new year!
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
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
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..
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
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
Hey Paul, thanks for your message! No, my snippet is generic and only compatible with default WooCommerce. Sorry 🙂
Wonderful, thank you! I’d always rather add a snippet than download yet another plugin if I can go that way. Good job.
Thank you! Just added it – was exactly what I needed.
Cheers Cathy – happy holidays then 🙂
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.
Excellent, thank you Tim 🙂
Thank you so much. The code worked perfectly. How can I operate the button “ON/OFF” switch in the WooCommerce settings.
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
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.
Cheers Charlotte 🙂
Hi, it worked pefectly! Thanks a lot, solves a big problem for me.
Just wanted to say “Thanks all”
That was awesome and so helpful when moving servers to put the old site on ice 😉
Great, thank you Thomaz!
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.
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 🙂
I think I found my solution – if I comment out the first 2 remove actions in your code –
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 ?
Yes, that looks perfect 🙂
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.
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 🙂
Thank you for this wonderful snippet, it works perfectly!!
And thank you for your wonderful feedback 🙂