Created
February 5, 2016 21:22
-
-
Save strangerstudios/7bab9a4838998f091c76 to your computer and use it in GitHub Desktop.
Count downgrades to free levels as "cancellations" in reports in Paid Memberships Pro.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Count downgrades to free levels as "cancellations" in reports. | |
Paste this into your active theme's functions.php or a custom plugin. | |
Requires PMPro v1.8.8 | |
*/ | |
function my_pmpro_reports_signups_sql($sqlQuery) { | |
//figure out which levels are free | |
$all_levels = pmpro_getAllLevels(true, true); | |
$free_levels = array(); | |
foreach($all_levels as $level) { | |
if(pmpro_isLevelFree($level)) | |
$free_levels[] = $level->id; | |
} | |
if(!empty($free_levels)) { | |
$sqlQuery = str_replace('AND mu2.id IS NULL', 'AND (mu2.id IS NULL || mu2.membership_id IN(' . implode(',', $free_levels) . '))', $sqlQuery); | |
} | |
return $sqlQuery; | |
} | |
add_filter('pmpro_reports_signups_sql', 'my_pmpro_reports_signups_sql'); | |
add_filter('pmpro_reports_get_cancellations_sql', 'my_pmpro_reports_signups_sql'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment