Paid Memberships Pro: Renewal Reminder Banner
Shows a banner across the top of the site to members whose level ends within the next few days, with a link to renew.
Opens WPIDE on
Code
if ( ! function_exists( 'pmpro_getMembershipLevelForUser' ) ) {
return;
}
$wpide_pmpro_warn_days = 7;
add_action( 'wp_body_open', function () use ( $wpide_pmpro_warn_days ) {
if ( ! is_user_logged_in() ) {
return;
}
$level = pmpro_getMembershipLevelForUser( get_current_user_id() );
if ( empty( $level->enddate ) ) {
return;
}
$left = (int) $level->enddate - time();
if ( $left < 0 || $left > $wpide_pmpro_warn_days * DAY_IN_SECONDS ) {
return;
}
printf(
'<div class="wpide-pmpro-renew" role="status" style="padding:.75em 1em;text-align:center;background:#fff4ce;color:#3c2f00">%1$s <a href="%2$s" style="color:inherit;font-weight:600">Renew now</a></div>',
esc_html( sprintf( 'Your %1$s membership ends on %2$s.', $level->name, wp_date( get_option( 'date_format' ), (int) $level->enddate ) ) ),
esc_url( pmpro_url( 'checkout', '?level=' . (int) $level->id ) )
);
} );
Notes
Only levels with an end date trigger the banner; automatically renewing subscriptions don't.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.