We’ve made some material updates to our Proration Add On. Our aim was to implement the most common proration use cases while making it easier to customize.
While enhancing the plugin and fixing what we considered bugs in the proration calculation, we made changes that may be unexpected for existing sites running the Add On. We expect most users will be happy with these changes, but if your site relied on the old math, please reach out to us in the forums and we can help you set up your desired proration model.
Below are more detailed explanations of each change as well as instructions on how to customize the updated Add On.
Change #1: The subtotal of the user’s last order is now used to calculate the pro-rated amount.
Prior to v.3, the proration calculation was performed using the “total” from the user’s last order. If you were calculating tax on your site, the total would include the tax. Now, the pretax amount is used in the calculation and taxes are applied after the pro-rated amount is determined.
Change #2: When upgrading (or sidegrading) to a level with a different payment period, a different proration calculation is used.
If the level the user is checking out for has a different payment period than their previous level (e.g. going from a monthly plan to an annual plan), the rules for prorating are basically:
- Calculate a credit based on how much time is left in the user’s current payment period,
- Apply that credit to the initial payment, and
- Set the new subscription to renew one (new) payment period out from the current date.
This is different from what is done when changing between levels with the same payment period (e.g. changing between monthly plans). In those cases, a pro-rated amount is calculated based on both the old and new levels based on how much time is left in the current pay period, and then the new subscription is setup to renew on the same date as the old subscription.
Change #3: We are rounding all dates down to the same hour/minute (midnight) when performing calculations.
This is a small change, and we can’t avoid this entirely, but rounding down the dates will minimize cases where users go to the checkout page and see one pro-rated amount and then come back later in the same day and see a different pro-rated amount. Most notably, if a user goes to change membership levels immediately after checking out, the credit for the current day will be applied to the pro-rated amount.
Customizing the Proration Add On
Instead of writing a custom proration plugin from scratch, we’d like users to be able to use the main Proration Add On with extra code in a customizations plugin to override the default behavior. This way, you’ll be able to use the helper functions provided by the Proration Add On and get updates to those functions as they are pushed out. (The next step for us would then be to add a wizard-like settings page to tweak the proration settings instead of using custom code.)
You can modify the behavior of the Proration Add On through hooks and filters or by overriding the main checkout level filter callback. Doing this will require a custom plugin and help from our team or a WordPress developer.
Filters in the PMPro Proration Add On
apply_filters( 'pmpro_is_downgrade', bool $is_downgrade, level_object $old_level, level_object $new_level);
Returns true if the new level is a downgrade from the old level.
apply_filters( 'pmpro_have_same_payment_period', bool $same_payment_period, level_object $old_level, level_object $new_level);
Returns true if the old and new levels have the same payment period
Overriding the Proration Rules
The main logic for how to prorate the levels can be found in the pmprorate_pmpro_checkout_level() function of the plugin. If you’d like to use different proration rules from the default, you can unhook our function and hook in a function of your own. Here is a template for how to do that.
More details can be found on the Proration Add On page.