verygoodplugins

Untitled

Jan 26th, 2021
1,058
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     $year            = 2020;
  2.     $year_to_compare = $year - 1;
  3.  
  4.     $args = array(
  5.         'number'     => -1,
  6.         'date_query' => array(
  7.             array(
  8.                 'year' => $year,
  9.             ),
  10.         ),
  11.     );
  12.  
  13.     $customers = new EDD_Customer_Query( $args );
  14.     $total     = count( $customers->items );
  15.  
  16.     for ( $i = 0; $i < 5; $i++ ) {
  17.  
  18.         $args = array(
  19.             'number'     => -1,
  20.             'date_query' => array(
  21.                 array(
  22.                     'year' => $year_to_compare,
  23.                 ),
  24.             ),
  25.         );
  26.  
  27.         $customers = new EDD_Customer_Query( $args );
  28.  
  29.         $total   = count( $customers->items );
  30.         $renewed = 0;
  31.  
  32.         foreach ( $customers->items as $customer ) {
  33.  
  34.             $args = array(
  35.                 'customer'   => $customer->id,
  36.                 'year'       => $year,
  37.                 'meta_key'   => '_edd_sl_is_renewal',
  38.                 'meta_value' => true,
  39.             );
  40.  
  41.             $payments = new EDD_Payments_Query( $args );
  42.  
  43.             $payments = $payments->get_payments();
  44.  
  45.             if ( ! empty( $payments ) ) {
  46.                 $renewed++;
  47.             }
  48.         }
  49.  
  50.         error_log( 'YEAR ' . $year_to_compare . ' vs ' . $year );
  51.         error_log( 'Total customers: ' . $total . '. Renewed in ' . $year . ': ' . $renewed );
  52.         error_log( 'Renewal rate: ' . ( $renewed / $total ) * 100 . '%' );
  53.  
  54.         $year_to_compare--;
  55.  
  56.     }
RAW Paste Data