Most free WooCommerce vacation mode snippets only give you a manual on/off switch – you turn it on before you leave and remember to turn it off when you’re back. If you forget, your store stays closed longer than it should.
This snippet fixes that by letting you set a start date and end date directly in the code. The store closes and reopens automatically based on those dates – no manual switch, no cron job needed.
The Snippet
/**
* WooCommerce Vacation Mode with scheduled start/end dates.
* Disables add to cart and checkout, and shows a notice, only during the set period.
*/
add_action( 'init', 'wpcodex_vacation_mode_check' );
function wpcodex_vacation_mode_check() {
$vacation_start = '2026-08-25 00:00:00'; // Change to your start date
$vacation_end = '2026-09-05 23:59:59'; // Change to your end date
$now = current_time( 'timestamp' );
if ( $now >= strtotime( $vacation_start ) && $now <= strtotime( $vacation_end ) ) {
// Disable add to cart button
add_filter( 'woocommerce_is_purchasable', '__return_false' );
// Block direct checkout access
add_action( 'template_redirect', function() {
if ( is_checkout() ) {
wp_safe_redirect( wc_get_cart_url() );
exit;
}
});
// Show a store notice
add_action( 'woocommerce_before_shop_loop', 'wpcodex_vacation_notice', 5 );
add_action( 'woocommerce_before_single_product', 'wpcodex_vacation_notice', 5 );
}
}
function wpcodex_vacation_notice() {
echo '<div class="woocommerce-info" style="text-align:center; font-weight:600;">
Our store is temporarily closed. We will be back soon - thank you for your patience!
</div>';
}
Where to add this: your child theme’s functions.php, a site-specific plugin, or a snippets plugin like WPCode.
How it works: every time a page loads, the snippet checks the current time against your two dates. If you’re inside that window, purchasing gets disabled and the notice shows up. Once the end date passes, everything goes back to normal automatically – you don’t need to log in and turn anything off.
A Note on Block Themes
If you’re using a block-based (Full Site Editing) theme, you may have noticed WooCommerce’s classic Store Notice option isn’t visible in the sidebar anymore. It hasn’t been removed – it’s just not linked anywhere in block themes yet. You can still reach it directly at /wp-admin/customize.php, or just rely on the notice this snippet already adds above the shop and product pages, which works regardless of theme type.
FAQ
Can customers still browse the store during vacation mode?
Yes. Browsing, product pages, and the cart page still work as normal – only the add-to-cart action and checkout are blocked during the set dates.
What happens to a cart a customer started before vacation mode began?
The cart items remain saved, but the customer won’t be able to proceed to checkout until the vacation period ends and the site auto-reopens.
Can I set more than one vacation period in advance?
Not with this exact snippet as written – it checks a single start and end date. For recurring or multiple scheduled closures, you’d need to expand the snippet to loop through an array of date ranges instead of two fixed variables.

