pmpro_getRevenue

The Paid Memberships Pro pmpro getRevenue function.

Description

pmpro_getRevenue( $period, (constant) $levels = NULL ); 

Parameters (2)

0. $period
The period.
1. $levels — Optional. (constant) => NULL
The levels.

Usage

  1. if ( !function_exists( 'pmpro_getRevenue' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'paid-memberships-pro/adminpages/reports/sales.php'; 
  3.  
  4. // The period. 
  5. $period = null; 
  6.  
  7. // The levels. 
  8. $levels = NULL; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = pmpro_getRevenue($period, $levels); 
  12.  

Defined (1)

The function is defined in the following location(s).

/adminpages/reports/sales.php  
  1. function pmpro_getRevenue($period, $levels = NULL) 
  2. //check for a transient 
  3. $cache = get_transient("pmpro_report_revenue"); 
  4. if(!empty($cache) && !empty($cache[$period]) && !empty($cache[$period][$levels])) 
  5. return $cache[$period][$levels];  
  6.  
  7. //a sale is anorderwith status NOT IN('refunded', 'review', token, error) 
  8. if($period == "today") 
  9. $startdate = date_i18n("Y-m-d", current_time('timestamp')); 
  10. elseif($period == "this month") 
  11. $startdate = date_i18n("Y-m", current_time('timestamp')) . "-01"; 
  12. elseif($period == "this year") 
  13. $startdate = date_i18n("Y", current_time('timestamp')) . "-01-01"; 
  14. else 
  15. $startdate = ""; 
  16.  
  17. $gateway_environment = pmpro_getOption("gateway_environment"); 
  18.  
  19. //build query 
  20. global $wpdb; 
  21. $sqlQuery = "SELECT SUM(total) FROM $wpdb->pmpro_membership_orders WHERE status NOT IN('refunded', 'review', token, error) AND timestamp >= '" . $startdate . "' AND gateway_environment = '" . esc_sql($gateway_environment) . "' "; 
  22.  
  23. //restrict by level 
  24. if(!empty($levels)) 
  25. $sqlQuery .= "AND membership_id IN(" . $levels . ") "; 
  26.  
  27. $revenue = $wpdb->get_var($sqlQuery); 
  28.  
  29. //save in cache 
  30. if(!empty($cache) && !empty($cache[$period])) 
  31. $cache[$period][$levels] = $revenue; 
  32. elseif(!empty($cache)) 
  33. $cache[$period] = array($levels => $revenue); 
  34. else 
  35. $cache = array($period => array($levels => $revenue)); 
  36.  
  37. set_transient("pmpro_report_revenue", $cache, 3600*24); 
  38.  
  39. return $revenue;