Skip to content

Instantly share code, notes, and snippets.

@dparker1005
Created January 16, 2020 19:53
Show Gist options
  • Save dparker1005/abe1873f724e80b636001974408c881b to your computer and use it in GitHub Desktop.
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.
<?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