Skip to content

Instantly share code, notes, and snippets.

@ideadude
Created February 17, 2018 16:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ideadude/1ab18a3a22ba52e8b2a4d7f631025d1a to your computer and use it in GitHub Desktop.
Save ideadude/1ab18a3a22ba52e8b2a4d7f631025d1a to your computer and use it in GitHub Desktop.
Override the default is_downgrade check in the PMPro Proration Add On
/**
* Override the default is_downgrade check in the PMPro Proration Add On
* Add this code to a custom plugin.
* A rank of level orders is used to calculate downgrades from upgrades.
* Be sure to change the $level_order array below as needed.
* You can also do your own calculation on the $old_level and $new_level objects.
*/
function pmpro_is_downgrade_custom_filter( $is_downgrade, $old_level, $new_level ) {
// this array contains all of the level ids in order of downgrade -> upgrade
// change this as needed
$level_order = array(4, 5, 6, 1, 2, 3);
// figure out where the levels rank
$old_level_rank = array_search( $old_level->id, $level_order );
$new_level_rank = array_search( $new_level->id, $level_order );
// make sure we have a rank for both levels, otherwise skip to let the plugin guess
if( $old_level_rank !== false && $new_level_rank !== false ) {
if( $old_level_rank > $new_level_rank ) {
$is_downgrade = true;
} else {
$is_downgrade = false;
}
}
return $is_downgrade;
}
add_filter( 'pmpro_is_downgrade', 'pmpro_is_downgrade_custom_filter', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment