public get_sales ( $form_id, $start_date = false, $end_date = false, $status = 'publish' ) : float | integer | ||
$form_id | int The donation form to retrieve stats for. If false, gets stats for all forms | |
$start_date | string|bool The starting date for which we'd like to filter our sale stats. If false, we'll use the default start date of `this_month` | |
$end_date | string|bool The end date for which we'd like to filter our sale stats. If false, we'll use the default end date of `this_month` | |
$status | string|array The sale status(es) to count. Only valid when retrieving global stats | |
return | float | integer | Total amount of donations based on the passed arguments. |
public function get_sales($form_id = 0, $start_date = false, $end_date = false, $status = 'publish')
{
$this->setup_dates($start_date, $end_date);
// Make sure start date is valid
if (is_wp_error($this->start_date)) {
return $this->start_date;
}
// Make sure end date is valid
if (is_wp_error($this->end_date)) {
return $this->end_date;
}
if (empty($form_id)) {
// Global sale stats
add_filter('give_count_payments_where', array($this, 'count_where'));
if (is_array($status)) {
$count = 0;
foreach ($status as $payment_status) {
$count += give_count_payments()->{$payment_status};
}
} else {
$count = give_count_payments()->{$status};
}
remove_filter('give_count_payments_where', array($this, 'count_where'));
} else {
$this->timestamp = false;
// Product specific stats
global $give_logs;
add_filter('posts_where', array($this, 'payments_where'));
$count = $give_logs->get_log_count($form_id, 'sale');
remove_filter('posts_where', array($this, 'payments_where'));
}
return $count;
}
/** * Test Get Sales by Date of Give Donation Form */ public function test_get_sales_by_date_of_give_form() { $stats = new Give_Payment_Stats(); $sales = $stats->get_sales($this->_new_form_id, 'this_month'); $this->assertEquals(2, $sales); }