Forked from andrewlimaza/pmpro-renew-membership-shortcode.php
Last active
December 22, 2021 20:22
-
-
Save travislima/caf4e40b75b913372e19692cff1b3644 to your computer and use it in GitHub Desktop.
Paid Memberships Pro Renew Membership Shortcode
This file contains 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; | |
} | |
// 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
This recipe is included in the blog post on "Insert a “Renew Membership” button via custom shortcode to display a renewal link/button for members." at Paid Memberships Pro here: https://www.paidmembershipspro.com/insert-a-renew-membership-button-via-custom-shortcode-to-display-a-renewal-link-button-for-members/