Forked from travislima/pmpro-renew-membership-shortcode.php
Last active
December 22, 2021 20:23
-
-
Save kimwhite/d70d34e89fdb27146129e66d5dfe9dcf to your computer and use it in GitHub Desktop.
Paid Memberships Pro Renew Membership Shortcode - with options to show within so many days of renewal
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 | |
/** | |
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
* The my_pmpro_renew_membership_shortcode is a custom function creating a renew link for members. | |
* Use the shortcode [pmpro_renew_button] to display the button anywhere on your site where shortcodes are recognized. | |
* | |
* @return string A link containing the URL string to renew. | |
*/ | |
function my_pmpro_renew_membership_shortcode() { | |
global $current_user, $pmpro_pages; | |
// Current user empty (i.e. not logged in) | |
if ( empty( $current_user ) ) { | |
return; | |
} | |
$level = pmpro_getMembershipLevelForUser( $current_user->ID ); | |
// If the user does not have a membership level, don't display anything. | |
if( empty( $level ) ) { | |
return; | |
} | |
if ( empty( $level->enddate ) ) { | |
return; | |
} | |
$days = 15; // Change this to value. | |
// Are we within the days until expiration? | |
$now = current_time( 'timestamp' ); | |
if ( $now + ( $days * 3600 * 24 ) < $level->enddate ) { | |
return; | |
} | |
// CSS Styling that changes link into a button. | |
?> | |
<style> | |
a.pmpro-renew-button { | |
background-color: #4CAF50; | |
border: none; | |
color: #fff; | |
padding: 15px 32px; | |
text-align: center; | |
text-decoration: none; | |
display: inline-block; | |
font-size: 16px; | |
} | |
</style> | |
<?php | |
$level_id = $level->id; | |
$url = add_query_arg( 'level', $level_id, get_permalink( $pmpro_pages['checkout'] ) ); | |
return '<a class="pmpro-renew-button" href="' . esc_url( $url ) . '">Renew Membership</a>'; | |
} | |
add_shortcode( 'pmpro_renew_button', 'my_pmpro_renew_membership_shortcode' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment