Forked from femiyb/pmpro-prorate-initial-payment.php
Last active
November 17, 2021 20:05
-
-
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.
This file contains 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
/** | |
* 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