Last active
February 27, 2019 14:34
-
-
Save femiyb/210d21e26412288122cc5f3e74ee6655 to your computer and use it in GitHub Desktop.
Change expiration level text and display number of days left
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
<?php | |
function change_text_for_pmpro_renewal( $text, $level ) { | |
// check if user is logged in else bail. | |
if( !is_user_logged_in() ) { | |
return $text; | |
} | |
global $current_user; | |
$membership = $current_user->membership_level; | |
// if logged in user doesn't have a membership level, bail. | |
if ( empty( $membership ) ) { | |
return $text; | |
} | |
$today = date( "d-m-Y" ); //get today's date | |
$user_enddate = $membership->enddate; | |
// If the user doesn't have an enddate set, bail. | |
if ( empty( $user_enddate ) ) { | |
return $text; | |
} | |
$days_left = ( $user_enddate - strtotime( $today ) ) / 86400; | |
// user is renewing. | |
if( $membership->ID == $level->id ) { | |
$text = 'You have ' . $days_left . ' days left on your plan. Once you renew, your membership will expire in ' . $level->expiration_number . ' ' . $level->expiration_period .'s.'; | |
} | |
return $text; | |
} | |
add_filter( 'pmpro_level_expiration_text', 'change_text_for_pmpro_renewal', 20, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment