Created
October 19, 2020 18:14
-
-
Save ronalfy/3cabb64b435749421c8ca9937d09174a to your computer and use it in GitHub Desktop.
PMPro - Force Renew on Expiring Members When Level Has No Expiration Date
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
<?php | |
/** | |
* Force-shows a renew button for users that have an expiration date and the level has no end date. | |
* | |
* You can add this recipe to your site by creating a custom plugin | |
* or using the Code Snippets plugin available for free in the WordPress repository. | |
* Read this companion article for step-by-step directions on either method. | |
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function show_renewal_link_expiring_members( $r, $level ) { | |
global $current_user; | |
if ( ! is_user_logged_in() || ! isset( $current_user->membership_levels ) ) { | |
return $r; | |
} | |
$has_expiring_level = false; | |
$level_id = 0; | |
foreach ( $current_user->membership_levels as $index => $membership_level ) { | |
$maybe_end_date = $membership_level->enddate; | |
if ( ! empty( $maybe_end_date ) ) { | |
$has_expiring_level = true; | |
$level_id = $membership_level->id; | |
break; | |
} | |
} | |
if ( $level_id == $level->ID ) { | |
return true; | |
} | |
return $r; | |
} | |
add_filter( 'pmpro_is_level_expiring_soon', 'show_renewal_link_expiring_members', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment