Skip to main content
Easy Digital Downloads Documentation
Documentation, Reference Materials, and Tutorials for Easy Digital Downloads

EDD_Payment_Stats

The 
EDD_Payment_Stats class is designed to provide a simple way to retrieve earnings and sales stats for the entire store, or specific products, for designated time periods, such as this week, last month, today, last year, etc.

To use 
EDD_Payment_Stats, you must instantiate a new instance of the class:

$stats = new EDD_Payment_Stats;

Once the class is instantiated, you can use any of the following member functions:

// Retrieve earnings
$stats->get_earnings( $download_id = 0, $start_date = false, $end_date = false );
// Retrieve sales
$stats->get_sales( $download_id = 0, $start_date = false, $end_date = false );
// Retrieve a list of the best selling Download products
$stats->get_best_selling( $number = 10 );

For both 
get_sales() and get_earnings(), the following parameters can be passed:

$download_id – The ID number of the product to retrieve stats for. If 0 or any other empty value is passed, stats will be retrieved for the whole store.

$start_date – The beginning date to retrieve stats for. If you want to retrieve stats for one of the pre-defined periods, simply pass the period, such as “today” or “yesterday”. This parameter can be a date string, a timestamp, or a date formatted in any standard format.

$end_date – The end date to retrieve stats for. If you want to retrieve stats for one of the pre-defined periods, leave this blank. This parameter can be a date string, a timestamp, or a date formatted in any standard format.

Stats can be retrieved for any pre-defined time period. These options include:

  • today
  • yesterday
  • this_week
  • last_week
  • this_month
  • last_month
  • this_quarter
  • last_quarter
  • this_year
  • last_year

Examples

// Store-wide sales for this month:
echo $stats->get_sales( 0, 'this_month' );

Returns an integer, the sum of sales in the given time span
// Store-wide earnings for August 2, 2013
echo $stats->get_earnings( 0, 'August 2, 2013' );

Returns an integer if earnings are a whole number, a float rounded to 2 if a 
fractional number, like 42.73
// Sales for download ID 44 from July 2 to August 5, 2013
echo $stats->get_sales( 44, 'July 2, 2013', 'August 5, 2013' );
// Earnings for download ID 52 for December 5, 2012
echo $stats->get_earnings( 52, '12-05-2012' )
$best_selling = $stats->get_best_selling( '10' );

Returns an array of the 10 best selling products, like this:

Array
(
    [0] => stdClass Object
        (
            [download_id] => 68
            [sales] => 3
        )

    [1] => stdClass Object
        (
            [download_id] => 120
            [sales] => 2
        )
)
Read our latest blog post:
Add More Stripe Payment Methods at Checkout