Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ideadude/76d411a7bb1c608159aafa16d4c4ab55 to your computer and use it in GitHub Desktop.
Save ideadude/76d411a7bb1c608159aafa16d4c4ab55 to your computer and use it in GitHub Desktop.
Prorate the initial payment. Useful for subscriptions that occur on the first of every month.
/**
* Prorate the initial payment at PMPro checkout based on the day of the month.
* You should use the Subscription Delays add on to set your subscription
* to delay until Y1-M1-01.
*/
function my_pmpro_checkout_level( $level ) {
$current_day = date( 'j' );
// Ignore if it's the first of the month.
if ( $current_day == 1 ) {
return $level;
}
$days_passed = $current_day - 1;
$days_in_month = date( 't' );
$level->initial_payment = pmpro_round_price( $level->initial_payment * ( ( $days_in_month - $days_passed ) / $days_in_month ) );
return $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