| @@ -8,9 +8,8 @@ | ||
| 8 | 8 | * Get the Total, Count, and Average of the payment totals for published donations of a given set of forms. |
| 9 | 9 | */ |
| 10 | 10 | class Query |
| 11 | 11 | { |
| 12 | - | |
| 13 | 12 | /** @var array */ |
| 14 | 13 | protected $formIDs; |
| 15 | 14 | |
| 16 | 15 | /** |
| @@ -28,14 +27,16 @@ | ||
| 28 | 27 | $this->formIDs = $formIDs; |
| 29 | 28 | } |
| 30 | 29 | |
| 31 | 30 | /** |
| 31 | + * @since 4.14.0 Replace {$wpdb->paymentmeta} with {$wpdb->donationmeta} | |
| 32 | + * @since 3.14.0 Consider the donation mode (test or live) instead of querying both modes together | |
| 32 | 33 | * @return string |
| 33 | 34 | */ |
| 34 | 35 | public function getSQL() |
| 35 | 36 | { |
| 36 | 37 | global $wpdb; |
| 37 | - | |
| 38 | + $mode = give_is_test_mode() ? 'test' : 'live'; | |
| 38 | 39 | $sql = " |
| 39 | 40 | SELECT |
| 40 | 41 | sum( revenue.amount ) as total, |
| 41 | 42 | count( payment.ID ) as count |
| @@ -41,15 +42,19 @@ | ||
| 41 | 42 | count( payment.ID ) as count |
| 42 | 43 | FROM {$wpdb->posts} as payment |
| 43 | 44 | JOIN {$wpdb->give_revenue} as revenue |
| 44 | 45 | ON revenue.donation_id = payment.ID |
| 46 | + JOIN {$wpdb->donationmeta} paymentMode | |
| 47 | + ON payment.ID = paymentMode.donation_id AND paymentMode.meta_key = '_give_payment_mode' | |
| 45 | 48 | WHERE |
| 46 | 49 | payment.post_type = 'give_payment' |
| 47 | 50 | AND |
| 48 | 51 | payment.post_status IN ( 'publish', 'give_subscription' ) |
| 52 | + AND | |
| 53 | + paymentMode.meta_value = '{$mode}' | |
| 49 | 54 | "; |
| 50 | 55 | |
| 51 | - if ( ! empty($this->formIDs)) { | |
| 56 | + if (!empty($this->formIDs)) { | |
| 52 | 57 | $sql .= ' |
| 53 | 58 | AND |
| 54 | 59 | revenue.form_id IN ( ' . $this->getFormsString() . ' ) |
| 55 | 60 | '; |