Created
November 4, 2021 10:33
-
-
Save andrewlimaza/c5c1a2d7a4f0a383e472f4e4810d1082 to your computer and use it in GitHub Desktop.
Keep pre-existing members on their initial checkout price when renewing their membership level.
This file contains 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 | |
/** | |
* Keep pre-existing members on their initial checkout price when manually renewing. Grandfather 'old' members when their levels pricing changes. | |
* Note: This is not needed for recurring membership levels and is designed for levels with an expiration date. | |
* | |
* 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/ | |
*/ | |
function my_pmpro_original_price_existing_members( $level ) { | |
global $current_user; | |
if ( ! is_user_logged_in() ) { | |
return $level; | |
} | |
// If they don't have a level already, just keep the price normal. | |
if ( ! pmpro_hasMembershipLevel() ) { | |
return $level; | |
} | |
$user_level = pmpro_getMembershipLevelForUser( $current_user->ID ); | |
if ( $level->id === $user_level->id ) { | |
// Let's adjust pricing here. | |
$last_order = new MemberOrder(); | |
$last_order->getLastMemberOrder( $current_user->ID, array('success','cancelled'), $user_level->id ); | |
// Only apply this to paid levels. | |
if ( $level->initial_payment > 0 ) { | |
$level->initial_payment = $last_order->subtotal; | |
} | |
} | |
// Set price billing to original price paid way back when. | |
return $level; | |
} | |
add_filter( 'pmpro_checkout_level', 'my_pmpro_original_price_existing_members', 10, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment