Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kimcoleman/82cee326dff6d39e25b192c0d226e745 to your computer and use it in GitHub Desktop.
Save kimcoleman/82cee326dff6d39e25b192c0d226e745 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() {
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 {
background-color: salmon;
}
.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();
// Bail if today is more than 7 days before enddate.
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' );
@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