Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function get_churn_by_year( $year = false ) {
- if ( ! isset( $_GET['churn'] ) || ! is_admin() ) {
- return;
- }
- $year = 2019;
- $year_to_compare = $year - 1;
- for ( $i = 0; $i < 4; $i++ ) {
- $args = array(
- 'number' => -1,
- 'date_query' => array(
- array(
- 'year' => $year_to_compare,
- ),
- ),
- );
- $customers = new EDD_Customer_Query( $args );
- $total = count( $customers->items );
- $renewed = 0;
- foreach ( $customers->items as $customer ) {
- $args = array(
- 'customer' => $customer->id,
- 'year' => $year,
- 'meta_key' => '_edd_sl_is_renewal',
- 'meta_value' => true,
- );
- $payments = new EDD_Payments_Query( $args );
- $payments = $payments->get_payments();
- if ( ! empty( $payments ) ) {
- $renewed++;
- }
- }
- error_log( 'YEAR ' . $year_to_compare . ' vs ' . $year );
- error_log( 'Total customers: ' . $total . '. Renewed in ' . $year . ': ' . $renewed );
- error_log( 'Renewal rate: ' . ( $renewed / $total ) * 100 . '%' );
- $year_to_compare--;
- }
- }
- add_action( 'init', 'get_churn_by_year' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement