Skip to content

Instantly share code, notes, and snippets.

@travislima
Last active November 10, 2020 03:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save travislima/b456811c9dfa7b2684585e2f5f5ac3c4 to your computer and use it in GitHub Desktop.
Save travislima/b456811c9dfa7b2684585e2f5f5ac3c4 to your computer and use it in GitHub Desktop.
Create a banner that will display a message to soon to be expiring members
<?php
/**
* This code will display a renewal reminder notification banner at the top of your website for members whose membership
* level will expire within 7 days of the date they visit your site.
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
* Note: When adding to your Customizations Plugin, be careful not to include the opening php tag on line 1 above.
*/
function pmpro_show_banner_renewal_message(){
// Bail early if the current user does not have a membership level.
if ( ! pmpro_hasMembershipLevel() ) {
return;
}
// Load custom CSS for banner.
?>
<style>
.pmpro_banner_renewal_wrapper{
width:100%;
height:4rem;
background-color:salmon;
}
.pmpro_banner_renewal_wrapper h4{
text-align:center;
color:white;
padding:1rem;
}
.pmpro_banner_renewal_wrapper a {
color:white;
text-decoration: underline;
}
.pmpro_banner_renewal_wrapper a:hover{
color:rgba(255,255,255,0.8);
}
</style>
<?php
$user_id = get_current_user_id();
$level = pmpro_getMembershipLevelForUser( $user_id );
// Bail if the user does not have an enddate set.
if ( empty( $level->enddate ) ) {
return;
}
$today = time();
// if today is more than 7 days before enddate, bail.
if ( $today <= strtotime( '- 7 days', $level->enddate ) ) {
return;
}
$message = "Your $level->name membership will expire soon. <a href=" . pmpro_url( "checkout", "?level=" . $level->id ) . "> Click here to renew membership.</a>";
echo '<div class="pmpro_banner_renewal_wrapper"><h4> ' . $message . ' </h4></div>';
}
add_action( 'wp_head', 'pmpro_show_banner_renewal_message' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment