Description

Usage

Parameters

$args

( array ) optional – Arguments provided by API Request

Returns

array

Source

File name: easy-digital-downloads/includes/api/class-edd-api.php

Lines: 1 to 100 of 258

publicfunctionget_stats($args=array()){$defaults=array('type'=>null,'product'=>null,'date'=>null,'startdate'=>null,'enddate'=>null);$args=wp_parse_args($args,$defaults);$dates=$this->get_dates($args);$stats=array();$earnings=array('earnings'=>array());$sales=array('sales'=>array());$error=array();if(!user_can($this->user_id,'view_shop_reports')&&!$this->override){return$stats;}if($args['type']=='sales'){if($args['product']==null){if($args['date']==null){$sales=$this->get_default_sales_stats();}elseif($args['date']==='range'){// Return sales for a date range
// Ensure the end date is later than the start date
if($args['enddate']<$args['startdate']){$error['error']=__('The end date must be later than the start date!','easy-digital-downloads');}// Ensure both the start and end date are specified
if(empty($args['startdate'])||empty($args['enddate'])){$error['error']=__('Invalid or no date range specified!','easy-digital-downloads');}$start_date=$dates['year'].'-'.$dates['m_start'].'-'.$dates['day_start'];$end_date=$dates['year_end'].'-'.$dates['m_end'].'-'.$dates['day_end'];$stats=EDD()->payment_stats->get_sales_by_range('other',true,$start_date,$end_date);foreach($statsas$sale){$key=$sale['y'].$sale['m'].$sale['d'];$sales['sales'][$key]=(int)$sale['count'];}$start_date=date('Y-m-d',strtotime($start_date));$end_date=date('Y-m-d',strtotime($end_date));while(strtotime($start_date)<=strtotime($end_date)){$d=date('d',strtotime($start_date));$m=date('m',strtotime($start_date));$y=date('Y',strtotime($start_date));$key=$y.$m.$d;if(!isset($sales['sales'][$key])){$sales['sales'][$key]=0;}$start_date=date('Y-m-d',strtotime('+1 day',strtotime($start_date)));}ksort($sales['sales']);$sales['totals']=array_sum($sales['sales']);}else{$start_date=$dates['year'].'-'.$dates['m_start'].'-'.$dates['day'];$end_date=$dates['year'].'-'.$dates['m_end'].'-'.$dates['day_end'];$stats=EDD()->payment_stats->get_sales_by_range($args['date'],false,$start_date,$end_date);if($statsinstanceofWP_Error){$error_message=__('There was an error retrieving earnings.','easy-digital-downloads');foreach($stats->errorsas$error_key=>$error_array){if(!empty($error_array[0])){$error_message=$error_array[0];}}$error['error']=sprintf('%s %s',$error_message,$args['date']);}else{if(empty($stats)){$sales['sales'][$args['date']]=0;}else{$total_sales=0;foreach($statsas$date){$total_sales+=(int)$date['count'];}$sales['sales'][$args['date']]=$total_sales;}}