Skip to content

Instantly share code, notes, and snippets.

@messica
Created July 9, 2019 18:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save messica/bcfcb51a1379d944dce4558ae8f53950 to your computer and use it in GitHub Desktop.
Save messica/bcfcb51a1379d944dce4558ae8f53950 to your computer and use it in GitHub Desktop.
Simple Proration for Upgrades Example
<?php
/**
* Simple Proration for Upgrades Example
*/
function my_pmpro_checkout_level( $checkout_level ) {
// Get user's current level.
$user_level = pmpro_getMembershipLevelForUser();
// Bail if there is no level or checking out for the same level.
if ( empty ( $user_level ) || $user_level->id == $checkout_level->id ) {
return $checkout_level;
}
// Calculate prorated cost based on current level settings.
$checkout_level->initial_payment = min( $checkout_level->initial_payment - $user_level->initial_payment, 0 );
return $checkout_level;
}
add_filter( 'pmpro_checkout_level', 'my_pmpro_checkout_level' );
@kimwhite
Copy link

Line 17 needs to be changed from "min" to "max"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment