Created
March 26, 2026 13:43
-
-
Save andrewlimaza/faf67c0555c972c29e2ef9a9a77093c4 to your computer and use it in GitHub Desktop.
Remove donation only level if it's the first level purchased or it's on it's own group.
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 donation only level if it's the first level purchased (including if it's your only level on your site). | |
| * Remove the "Donation Only Level" setting from the level if you want members to keep this level. | |
| * | |
| * To implement this code onto your site follow this guide - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
| */ | |
| function my_pmprodon_pmpro_checkout_before_change_membership_level( $user_id, $morder ) { | |
| global $pmprodon_existing_member_flag, $pmpro_level; | |
| if ( ! empty( $pmpro_level ) && pmprodon_is_donations_only( $pmpro_level->id ) ) { | |
| if ( pmpro_hasMembershipLevel() ) { | |
| add_filter( 'pmpro_cancel_previous_subscriptions', '__return_false' ); | |
| add_filter( 'pmpro_deactivate_old_levels', '__return_false' ); | |
| } | |
| $pmprodon_existing_member_flag = true; // This is really used as a flag to remove the level when it's a donations level to remove the level after checkout. | |
| } | |
| } | |
| remove_action( 'pmpro_checkout_before_change_membership_level', 'pmprodon_pmpro_checkout_before_change_membership_level', 0, 2 ); | |
| add_action( 'pmpro_checkout_before_change_membership_level', 'my_pmprodon_pmpro_checkout_before_change_membership_level', 1, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment