Created
July 2, 2026 11:33
-
-
Save dwanjuki/4987867687167d19176f8fa1509e9bf6 to your computer and use it in GitHub Desktop.
Charge the level's Billing Amount instead of the Initial Payment when an existing member checks out to manually renew their current level.
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 | |
| /** | |
| * Charge the level's Billing Amount instead of the Initial Payment when an | |
| * existing member checks out to manually renew their current level. | |
| * | |
| * Only applies to members who have been continuously active on that level | |
| * for at least the number of months set in MY_PMPRO_RENEWAL_ACTIVE_MONTHS below. | |
| * | |
| * 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. | |
| * Read this companion article for step-by-step directions on either method: | |
| * https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
| */ | |
| // How many months a member must have been active to get the renewal price. | |
| define( 'MY_PMPRO_RENEWAL_ACTIVE_MONTHS', 6 ); | |
| function my_pmpro_renewal_billing_amount_at_checkout( $level ) { | |
| // Bail if there's no level or the visitor isn't logged in. | |
| if ( empty( $level ) || ! is_user_logged_in() ) { | |
| return $level; | |
| } | |
| // Only adjust pricing when the member is renewing the level they already have. | |
| if ( ! pmpro_hasMembershipLevel( $level->id ) ) { | |
| return $level; | |
| } | |
| // Bail if the level has no recurring Billing Amount to fall back on. | |
| if ( empty( $level->billing_amount ) ) { | |
| return $level; | |
| } | |
| // Get the start date (timestamp) of the member's current active membership for this level. | |
| $startdate = pmpro_getMemberStartdate( get_current_user_id(), $level->id ); | |
| if ( empty( $startdate ) ) { | |
| return $level; | |
| } | |
| // Bail if they haven't been active long enough yet. | |
| $cutoff = strtotime( '-' . absint( MY_PMPRO_RENEWAL_ACTIVE_MONTHS ) . ' months', current_time( 'timestamp' ) ); | |
| if ( $startdate > $cutoff ) { | |
| return $level; | |
| } | |
| // Qualified renewal: charge the Billing Amount today instead of the Initial Payment. | |
| $level->initial_payment = $level->billing_amount; | |
| return $level; | |
| } | |
| // Priority 5 so this runs before the Auto-Renewal Checkbox Add On (priority 7), | |
| // which zeroes out billing_amount when a member opts out of auto-renewal. | |
| add_filter( 'pmpro_checkout_level', 'my_pmpro_renewal_billing_amount_at_checkout', 5 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment