Created
January 16, 2020 19:53
-
-
Save dparker1005/abe1873f724e80b636001974408c881b to your computer and use it in GitHub Desktop.
Prorate the initial payment of a membership while using PMPro Set Expiration Date.
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 | |
// Copy from below here... | |
/* | |
* Prorate the initial payment of a membership while using PMPro Set Expiration Date. | |
* | |
* For year-long proration cycles, leave as is. | |
* | |
* For partial year cycles (such as classes between September and May), change $days_to_prorate to the number | |
* of days between the start and end of classes. | |
*/ | |
function my_pmpro_custom_prorate( $level ) { | |
$days_to_prorate = 365; // By default, prorate the entire year | |
if ( $level->expiration_period === 'Day' && $level->expiration_number < $days_to_prorate ) { | |
// Multiply initial payment by how far we are in the prorating period | |
$level->initial_payment = $level->initial_payment*($level->expiration_number/$days_to_prorate); | |
} | |
return $level; | |
} | |
add_filter('pmpro_checkout_level', 'my_pmpro_custom_prorate', 11, 1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment