Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save travislima/caf4e40b75b913372e19692cff1b3644 to your computer and use it in GitHub Desktop.
Save travislima/caf4e40b75b913372e19692cff1b3644 to your computer and use it in GitHub Desktop.
Paid Memberships Pro Renew Membership Shortcode
<?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' );
@laurenhagan0306
Copy link

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/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment