# Start and End Scheduled Sales on the Hour

> Checks scheduled sale dates every hour instead of once a day at midnight, so sales that should start or end during the day do so close to on time.

- Type: PHP
- Runs: Run everywhere
- Category: [WooCommerce](https://wpide.com/library/category/woocommerce/)
- Requires: WooCommerce
- Tags: woocommerce, sale, schedule, cron
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/woo-hourly-scheduled-sales/

## Code

```php
add_action( 'init', function () {
    if ( ! wp_next_scheduled( 'wpide_hourly_scheduled_sales' ) ) {
        wp_schedule_event( time() + 300, 'hourly', 'wpide_hourly_scheduled_sales' );
    }
} );

add_action( 'wpide_hourly_scheduled_sales', function () {
    if ( function_exists( 'wc_scheduled_sales' ) ) {
        wc_scheduled_sales();
    }
} );
```

## Notes

WooCommerce sale dates are whole days, so this mainly helps sites where the midnight check runs late.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Start and End Scheduled Sales on the Hour" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
