Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save davidmutero/7ba9c89d03a0ab8afbdb123c7842dea0 to your computer and use it in GitHub Desktop.

Select an option

Save davidmutero/7ba9c89d03a0ab8afbdb123c7842dea0 to your computer and use it in GitHub Desktop.
Hide the Cancel Membership Link for Expiring Memberships
<?php
/**
* Remove the Cancel membership action link for memberships
* that already have an expiration date.
*
* Members whose level has an enddate will not see the
* Cancel link on the Membership Account page.
*
* You can add this recipe to your PMPro Customizations Plugin
* or use the Code Snippets plugin.
*
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
/**
* Hide the Cancel link for expiring memberships.
*
* @param array $pmpro_member_action_links Existing account action links.
* @return array Modified action links.
*/
function my_pmpro_hide_cancel_button_for_expiring_memberships( $pmpro_member_action_links ) {
$current_user = wp_get_current_user();
// Bail if cancel link is already removed.
if ( ! isset( $pmpro_member_action_links['cancel'] ) ) {
return $pmpro_member_action_links;
}
// Get current membership level.
$level = pmpro_getMembershipLevelForUser( $current_user->ID );
// Bail if no membership level exists.
if ( empty( $level ) ) {
return $pmpro_member_action_links;
}
// Remove cancel link if membership has an expiration date.
if ( ! empty( $level->enddate ) ) {
unset( $pmpro_member_action_links['cancel'] );
}
return $pmpro_member_action_links;
}
add_filter( 'pmpro_member_action_links', 'my_pmpro_hide_cancel_button_for_expiring_memberships' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment