# EDD Earnings This Month vs Last Month Widget

> Adds a dashboard widget with this month's Easy Digital Downloads earnings and order count next to last month's totals, using EDD's own stats engine.

- Type: PHP
- Runs: Admin only
- Category: [Easy Digital Downloads](https://wpide.com/library/category/edd/)
- Requires: Easy Digital Downloads
- Tags: edd, dashboard, reports, earnings
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/edd-dashboard-month-earnings/

## Code

```php
add_action( 'wp_dashboard_setup', function () {
    if ( ! class_exists( '\EDD\Stats' ) || ! current_user_can( 'view_shop_reports' ) ) {
        return;
    }

    wp_add_dashboard_widget( 'wpide_edd_month', 'Earnings this month', function () {
        $data = get_transient( 'wpide_edd_month_earnings' );

        if ( false === $data ) {
            $stats = new \EDD\Stats();
            $data  = array(
                'this_earnings' => (float) $stats->get_order_earnings( array( 'range' => 'this_month' ) ),
                'this_orders'   => (int) $stats->get_order_count( array( 'range' => 'this_month' ) ),
                'last_earnings' => (float) $stats->get_order_earnings( array( 'range' => 'last_month' ) ),
                'last_orders'   => (int) $stats->get_order_count( array( 'range' => 'last_month' ) ),
            );
            set_transient( 'wpide_edd_month_earnings', $data, 30 * MINUTE_IN_SECONDS );
        }

        $money = function ( $amount ) {
            return esc_html( html_entity_decode( edd_currency_filter( edd_format_amount( $amount ) ) ) );
        };

        printf(
            '<p style="font-size:24px;margin:.2em 0"><strong>%1$s</strong></p><p>%2$s</p><p>%3$s</p>',
            $money( $data['this_earnings'] ), // phpcs:ignore WordPress.Security.EscapeOutput -- Escaped in $money.
            esc_html( sprintf( '%d orders this month', $data['this_orders'] ) ),
            esc_html( sprintf( 'Last month: %1$s from %2$d orders.', html_entity_decode( edd_currency_filter( edd_format_amount( $data['last_earnings'] ) ) ), $data['last_orders'] ) )
        );
    } );
} );
```

## Notes

Only users who can view shop reports see it, and the figures are cached for 30 minutes.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "EDD Earnings This Month vs Last Month 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/
