Halloween Sale 15% off Ends in See the plans
PHP

Store Vacation Mode

Pauses all purchasing between two dates and shows a store-wide notice explaining when you will be back, while the catalog stays online.

Don’t have WPIDE yet? Install it on your site

Code

$wpide_vacation = array(
    'start'   => '2026-12-23',   // First day closed (YYYY-MM-DD).
    'end'     => '2027-01-02',   // Last day closed.
    'message' => 'We are on a short break. Orders placed now will ship after January 3.',
);

$wpide_on_vacation = function () use ( $wpide_vacation ) {
    $today = wp_date( 'Y-m-d' );

    return $today >= $wpide_vacation['start'] && $today <= $wpide_vacation['end'];
};

add_filter( 'woocommerce_is_purchasable', function ( $purchasable ) use ( $wpide_on_vacation ) {
    return $wpide_on_vacation() ? false : $purchasable;
}, 99 );

add_filter( 'woocommerce_variation_is_purchasable', function ( $purchasable ) use ( $wpide_on_vacation ) {
    return $wpide_on_vacation() ? false : $purchasable;
}, 99 );

add_action( 'wp_body_open', function () use ( $wpide_on_vacation, $wpide_vacation ) {
    if ( $wpide_on_vacation() ) {
        echo '<div class="wpide-vacation-notice" style="padding:10px 16px;background:#fcf9e8;border-bottom:1px solid #dba617;text-align:center;">' . esc_html( $wpide_vacation['message'] ) . '</div>';
    }
} );

Notes

Dates use the site timezone. Purchasing resumes automatically after $end.

How to add this snippet

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.