Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save JarrydLong/5802520c54c9b0567244678f467e2b45 to your computer and use it in GitHub Desktop.
Save JarrydLong/5802520c54c9b0567244678f467e2b45 to your computer and use it in GitHub Desktop.
Change when user can renew their membership PMPro
<?php
/**
* Allow members to only renew if their membership expires in 45 days or less.
* Only do this for levels that are not recurring.
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function custom_pmpro_is_level_expiring_soon( $r, $level ) {
if( $level->billing_amount > 0 ) {
return $r; //dont change for recurring levels
}
$days = 45; //change number of days before someone is allowed to renew.
$r = false;
$now = current_time('timestamp');
if( $now + ($days*3600*24) >= $level->enddate ) {
$r = true;
}
return $r;
}
add_filter( 'pmpro_is_level_expiring_soon', 'custom_pmpro_is_level_expiring_soon', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment