Last active
November 10, 2020 03:14
-
-
Save itsjusteileen/bc831761a17047c40b22136abd9b5540 to your computer and use it in GitHub Desktop.
Create a renewal banner for PMPro sites using the Multiple Memberships Per User Add On
This file contains hidden or 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 | |
/** | |
* 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_mmpu_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 ); | |
$current_levels = pmpro_getMembershipLevelsForUser( $user->ID ); | |
$message = ''; | |
// $message = print_r( $current_levels ); | |
foreach ( $current_levels as $key => $value ) { | |
// $my_levels[] = $value->id . ' = ' . $value->name . '<br>'; | |
$message .= 'You have level ' . $value->id . ' = ' . $value->name . '<br>'; | |
} | |
// 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(); | |
$alllevels = pmpro_getAllLevels( true, true ); | |
// 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 '<a href="' . get_permalink( $pmpro_pages['account'] ) . '" target="_blank"><div class="pmpro_banner_renewal_wrapper banner banner_secondary"><h4> ' . $message . ' </h4></div></a>'; | |
} | |
add_action( 'before_page', 'pmpro_mmpu_show_banner_renewal_message' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment