Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save kimcoleman/03df8ada08aafe252dd685c431d57a2f to your computer and use it in GitHub Desktop.
Save kimcoleman/03df8ada08aafe252dd685c431d57a2f to your computer and use it in GitHub Desktop.
Display a banner that notifies users about their upcoming expiration - Memberlite method.
<?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 memberlite_show_banner_renewal_message(){
global $pmpro_pages;
// 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 h4 {
color: white;
margin: 0;
padding: 1rem;
text-align: center;
}
.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 this is the checkout page.
if ( is_page( $pmpro_pages['checkout'] ) ) {
return;
}
// 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 banner banner_secondary"><h4> ' . $message . ' </h4></div>';
}
add_action( 'before_page', 'memberlite_show_banner_renewal_message' );
@laurenhagan0306
Copy link

This recipe is included in the blog post on "Add a customized notification banner to alert your members of upcoming expiration." at Paid Memberships Pro here: https://www.paidmembershipspro.com/add-a-customized-notification-banner-to-alert-your-members-of-upcoming-expiration/

@kimwhite
Copy link

Not compatible with Multiple Memberships Per User Add On. Will only show the most recent order information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment