Override the default is_downgrade check in the PMPro Proration Add On
This file contains 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
/** | |
* 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