• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
Easy Digital Downloads a2z

Easy Digital Downloads a2z

Easy Digital Downloads a2z

  • Home
  • Plugins
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / EDD_Batch_Earnings_Report_Export::get_data() – Get the Export Data.

You appear to be a bot. Output may be restricted

Description

Get the Export Data.

Usage

$array = EDD_Batch_Earnings_Report_Export::get_data();

Parameters

Returns

array $data The data for the CSV file

Source

File name: easy-digital-downloads/includes/admin/reporting/export/class-batch-export-earnings-report.php
Lines:

1 to 59 of 59
  public function get_data() {
    global $wpdb;

    $data = array();

    $start_date = date( 'Y-m-d 00:00:00', strtotime( $this->start ) );
    $end_date   = date( 'Y-m-t 23:59:59', strtotime( $this->start ) );

    if ( $this->step > 1 ) {
      $start_timestamp = strtotime( 'first day of +' . ( $this->step - 1 ) . ' month', strtotime( $start_date ) );
      $start_date      = date( 'Y-m-d 00:00:00', $start_timestamp );
      $end_date        = date( 'Y-m-t 23:59:59', $start_timestamp );
    }

    if ( strtotime( $start_date ) > strtotime( $this->end ) ) {
      return false;
    }

    $statuses = $this->get_supported_statuses();
    $totals   = $wpdb->get_results( $wpdb->prepare(
      "SELECT SUM(meta_value) AS total, COUNT(DISTINCT posts.ID) AS count, posts.post_status AS status
			 FROM {$wpdb->posts} AS posts
			 INNER JOIN {$wpdb->postmeta} ON posts.ID = {$wpdb->postmeta}.post_ID
			 WHERE posts.post_type IN ('edd_payment')
			 AND {$wpdb->postmeta}.meta_key = '_edd_payment_total'
			 AND posts.post_date >= %s
			 AND posts.post_date <= %s
			 GROUP BY YEAR(posts.post_date), MONTH(posts.post_date), posts.post_status
			 ORDER by posts.post_date ASC", $start_date, $end_date ), ARRAY_A );

    $total_data = array();
    foreach ( $totals as $row ) {
      $total_data[ $row['status'] ] = array(
        'count'  => $row['count'],
        'amount' => $row['total']
      );
    }

    foreach ( $statuses as $status ) {

      if ( ! isset( $total_data[ $status ] ) ) {
        $data[ $status ] = array(
          'count'  => 0,
          'amount' => 0,
        );
      } else {
        $data[ $status ] = array(
          'count'  => $total_data[ $status ]['count'],
          'amount' => $total_data[ $status ]['amount'],
        );
      }

    }

    $data = apply_filters( 'edd_export_get_data', $data );
    $data = apply_filters( 'edd_export_get_data_' . $this->export_type, $data, $start_date, $end_date );

    return $data;
  }
 

 View on GitHub View on Trac

Published: 26th November 2019 | Last updated: 26th January 2022

Primary Sidebar

Information

Function name: EDD_Batch_Earnings_Report_Export::get_data
Class ref: EDD_Batch_Earnings_Report_Export
Plugin ref: Easy Digital Downloads
Version: 2.11.6
Sourcefile: includes/admin/reporting/export/class-batch-export-earnings-report.php
File ref: includes/admin/reporting/export/class-batch-export-earnings-report.php
Deprecated?: No
API Letters: B,E,R

Footer

Easy Digital Downloads a2z
Easy Digital Downloads a2z
Easy Digital Downloads a2z
WordPress 5.9.3
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  edd.wp-a2z.org
© Copyright Easy Digital Downloads a2z 2014-2022. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites