# Low Stock Products Dashboard Widget

> Lists WooCommerce products that are running low or out of stock, so you can reorder before customers notice.

- Type: PHP
- Runs: Admin only
- Category: [Dashboard](https://wpide.com/library/category/dashboard/)
- Requires: WooCommerce
- Tags: dashboard, widget, woocommerce
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/woo-low-stock-widget/

## Code

```php
add_action( 'wp_dashboard_setup', function () {
    if ( ! function_exists( 'wc_get_products' ) || ! current_user_can( 'edit_products' ) ) {
        return;
    }

    wp_add_dashboard_widget( 'wpide_woo_low_stock', 'Low Stock', function () {
        $threshold = (int) get_option( 'woocommerce_notify_low_stock_amount', 2 );
        $products  = wc_get_products( array(
            'limit'        => 15,
            'manage_stock' => true,
            'stock_status' => array( 'instock', 'outofstock', 'onbackorder' ),
            'orderby'      => 'meta_value_num',
            'meta_key'     => '_stock',
            'order'        => 'ASC',
            'type'         => array( 'simple', 'variation' ),
        ) );

        $rows = array();
        foreach ( $products as $product ) {
            if ( (int) $product->get_stock_quantity() <= $threshold ) {
                $rows[] = $product;
            }
        }

        if ( ! $rows ) {
            echo '<p>All tracked products are above the low stock threshold.</p>';
            return;
        }

        echo '<table class="widefat striped"><tbody>';
        foreach ( $rows as $product ) {
            $edit_id = $product->get_parent_id() ? $product->get_parent_id() : $product->get_id();
            printf(
                '<tr><td><a href="%1$s">%2$s</a></td><td style="text-align:right;%3$s">%4$d</td></tr>',
                esc_url( get_edit_post_link( $edit_id ) ),
                esc_html( $product->get_name() ),
                $product->get_stock_quantity() <= 0 ? 'color:#d63638;font-weight:600' : '',
                (int) $product->get_stock_quantity()
            );
        }
        echo '</tbody></table>';
    } );
} );
```

## Notes

Uses the low stock threshold from WooCommerce > Settings > Products > Inventory.

## How to use it

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