Created
July 9, 2019 18:47
-
-
Save messica/bcfcb51a1379d944dce4558ae8f53950 to your computer and use it in GitHub Desktop.
Simple Proration for Upgrades Example
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 | |
/** | |
* 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' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line 17 needs to be changed from "min" to "max"