# Daily Low Stock Digest Email

> Sends one email each morning listing every product at or below your low stock threshold, instead of a separate alert per product.

- Type: PHP
- Runs: Run everywhere
- Category: [WooCommerce](https://wpide.com/library/category/woocommerce/)
- Requires: WooCommerce
- Tags: woocommerce, inventory, email, stock
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/woo-low-stock-daily-digest/

## Code

```php
$wpide_digest_to = ''; // Recipient; empty uses the WooCommerce stock email recipient or admin email.

add_action( 'init', function () {
    if ( ! wp_next_scheduled( 'wpide_low_stock_digest' ) ) {
        wp_schedule_event( strtotime( 'tomorrow 07:00' ) - (int) ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ), 'daily', 'wpide_low_stock_digest' );
    }
} );

add_action( 'wpide_low_stock_digest', function () use ( $wpide_digest_to ) {
    global $wpdb;

    if ( ! function_exists( 'WC' ) ) {
        return;
    }

    $threshold = (int) get_option( 'woocommerce_notify_low_stock_amount', 2 );
    $rows      = $wpdb->get_results( $wpdb->prepare(
        "SELECT l.product_id, l.sku, l.stock_quantity FROM {$wpdb->wc_product_meta_lookup} l
         INNER JOIN {$wpdb->posts} p ON p.ID = l.product_id AND p.post_status = 'publish'
         WHERE l.stock_quantity IS NOT NULL AND l.stock_quantity <= %d
         ORDER BY l.stock_quantity ASC LIMIT 200",
        $threshold
    ) );

    if ( ! $rows ) {
        return;
    }

    $lines = '';

    foreach ( $rows as $row ) {
        $lines .= sprintf( '<tr><td><a href="%1$s">%2$s</a></td><td>%3$s</td><td style="text-align:right">%4$s</td></tr>', esc_url( admin_url( 'post.php?action=edit&post=' . ( wp_get_post_parent_id( $row->product_id ) ?: $row->product_id ) ) ), esc_html( get_the_title( $row->product_id ) ), esc_html( $row->sku ), esc_html( wc_stock_amount( $row->stock_quantity ) ) );
    }

    $to      = $wpide_digest_to ? $wpide_digest_to : get_option( 'woocommerce_stock_email_recipient', get_option( 'admin_email' ) );
    $mailer  = WC()->mailer();
    $content = '<table style="width:100%;border-collapse:collapse" cellpadding="6"><tr><th style="text-align:left">Product</th><th style="text-align:left">SKU</th><th style="text-align:right">Stock</th></tr>' . $lines . '</table>';

    $mailer->send( $to, sprintf( '%d products are low on stock', count( $rows ) ), $mailer->wrap_message( 'Low stock digest', $content ) );
} );
```

## Notes

Uses the low stock threshold from WooCommerce > Settings > Products > Inventory and sends nothing on days when no product is low.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Daily Low Stock Digest Email" 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/
