Forked from ipokkel/pmpro-remove-cancel-link-from-account-page-per-level.php
Last active
June 18, 2025 12:05
-
-
Save davidmutero/4817fa56291806cc8ee6c71f9dea78bb to your computer and use it in GitHub Desktop.
Remove “Cancel” Link from Account Page Per Level and Specific Payment Plan
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 | |
/** | |
* Remove the "Cancel" membership action link from the account page | |
* for users with specific membership levels AND a monthly recurring payment plan. | |
* | |
* You can add this recipe to your site by creating a custom plugin | |
* or using the Code Snippets plugin available for free in the WordPress repository. | |
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function my_pmpro_remove_cancel_link_monthly_plan( $pmpro_member_action_links ) { | |
// Define targeted level IDs. | |
$target_levels = array( 1, 2, 3 ); // Update with your level IDs | |
$membership_level = pmpro_getMembershipLevelForUser(); | |
if ( empty( $membership_level ) ) { | |
return $pmpro_member_action_links; | |
} | |
// Check if user has one of the target levels. | |
if ( in_array( (int) $membership_level->id, $target_levels, true ) ) { | |
// Check if the user's plan is monthly recurring. | |
if ( | |
isset( $membership_level->cycle_number ) && | |
isset( $membership_level->cycle_period ) && | |
$membership_level->cycle_number == 1 && | |
strtolower( $membership_level->cycle_period ) === 'month' | |
) { | |
// Remove the cancel link. | |
unset( $pmpro_member_action_links['cancel'] ); | |
} | |
} | |
return $pmpro_member_action_links; | |
} | |
add_filter( 'pmpro_member_action_links', 'my_pmpro_remove_cancel_link_monthly_plan', 10, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment