Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save JarrydLong/83fa23cc3c36de8ae725b0ee803b43a4 to your computer and use it in GitHub Desktop.

Select an option

Save JarrydLong/83fa23cc3c36de8ae725b0ee803b43a4 to your computer and use it in GitHub Desktop.
<?php //do not copy
/**
* This recipe will set the initial amount to the billing amount for a member
* that has an expiration date and is renewing.
*
*/
function my_pmpro_change_initial_amount_existing_members( $level ) {
if ( ! is_user_logged_in() ) {
return $level;
}
global $current_user;
$pmpro_level = pmpro_getLevel( $level->id );
// must hardcode to recurring amount
$initial_amount = $pmpro_level->billing_amount;
// Get current active membership levels for this user
$user_levels = pmpro_getMembershipLevelsForUser( $current_user->ID );
if ( ! empty( $user_levels ) ) {
foreach ( $user_levels as $user_level ) {
if ( (int) $user_level->id === (int) $level->id ) {
// Check if this level has an expiration date
if ( ! empty( $user_level->enddate ) ) {
$level->initial_payment = $initial_amount;
return $level;
}
}
}
}
return $level;
}
add_filter( 'pmpro_checkout_level', 'my_pmpro_change_initial_amount_existing_members', 99, 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment