# Keep WooCommerce Logs for 7 Days

> Makes WooCommerce delete its log entries (payment gateways, shipping, webhooks and more) after 7 days instead of 30, keeping the log table and folder small.

- Type: PHP
- Runs: Run everywhere
- Category: [Performance](https://wpide.com/library/category/performance/)
- Requires: WooCommerce
- Tags: woocommerce, logs, database
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/perf-woo-log-retention/

## Code

```php
// Days to keep WooCommerce logs.
$wpide_wc_log_days = 7;

add_filter( 'woocommerce_logger_days_to_retain_logs', function () use ( $wpide_wc_log_days ) {
    return (int) $wpide_wc_log_days;
} );
```

## Notes

Raise the number while you are debugging a payment or shipping problem.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Keep WooCommerce Logs for 7 Days" 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/
