Created
March 17, 2020 19:56
-
-
Save ideadude/58a0e10c609b332024819b0d130205b0 to your computer and use it in GitHub Desktop.
Discounts when purchasing multiple levels with PMPro MMPU
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
| /** | |
| * Discounts when purchasing multiple levels with PMPro MMPU | |
| * | |
| * 1. Add this to a custom plugin or code snippet. | |
| * 2. Adjust the discount_levels array. | |
| * 3. Adjust the logic for when the price is changed and how much. | |
| * 4. Make sure to remove the billing_amount lines if you don't have recurring billing. | |
| */ | |
| function my_pmpro_checkout_level_discounts( $level ) { | |
| $discount_levels = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ); | |
| if ( isset( $_REQUEST['level'] ) ) { | |
| $level_ids = array_map( 'intval', explode( "+", preg_replace( "[^0-9\+]", "", $_REQUEST['level'] ) ) ); | |
| $count = count( array_intersect( $discount_levels, $level_ids ) ); | |
| if ( $count > 1 ) { | |
| // $5 off for the second level | |
| $level->initial_payment = $level->initial_payment - 5; | |
| $level->billing_amount = $level->billing_amount - 5; | |
| } | |
| if ( $count > 2 ) { | |
| // $2 off for each additional level past 2 | |
| $level->initial_payment = $level->initial_payment - ($count - 1)*2; | |
| $level->billing_amount = $level->billing_amount - ($count - 1)*2; | |
| } | |
| // make sure we're > $5 | |
| $level->initial_payment = max( 5, $level->initial_payment ); | |
| $level->billing_amount = max( 5, $level->billing_amount ); | |
| // make sure we're formatted correctly | |
| $level->initial_payment = pmpro_round_price( $level->initial_payment ); | |
| $level->billing_amount = pmpro_round_price( $level->billing_amount ); | |
| } | |
| return $level; | |
| } | |
| add_filter( 'pmpro_checkout_level', 'my_pmpro_checkout_level_discounts' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment