Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save dwanjuki/28ac7e7e517de41e7836e36dc9dcec3d to your computer and use it in GitHub Desktop.

Select an option

Save dwanjuki/28ac7e7e517de41e7836e36dc9dcec3d to your computer and use it in GitHub Desktop.
Maintain Initial Payment amount from original checkout when members renew Level 1.
<?php
/**
* Maintain Initial Payment amount from original checkout when members renew
* level 1. Keeps existing active members on old price after changing level cost.
*
* 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_maintain_initial_payment_amount_on_renewal( $level ) {
global $current_user;
// Bail if user isn't logged in.
if ( empty( $current_user->ID ) ) {
return $level;
}
// Bail if not a level 1 checkout.
if ( 1 !== (int) $level->id ) {
return $level;
}
// Bail if user does not have level 1.
if ( ! pmpro_hasMembershipLevel( 1 ) ) {
return $level;
}
// Get amount paid by member for level 1.
$user_level = pmpro_getSpecificMembershipLevelForUser( $current_user->ID, 1 );
$user_paid = (float) $user_level->initial_payment;
// Get level 1 checkout price.
$level_price = (float) $level->initial_payment;
// Bail if checkout price and last payment amount are equal.
if ( $level_price === $user_paid ) {
return $level;
}
// Last initial payment amount is different from current level cost.
// Set checkout price to last payment amount.
$level->initial_payment = $user_paid;
return $level;
}
add_filter( 'pmpro_checkout_level', 'my_pmpro_maintain_initial_payment_amount_on_renewal' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment