Last active
October 30, 2020 21:35
-
-
Save strangerstudios/d0b06dbb36483a76b030 to your computer and use it in GitHub Desktop.
PMPro Early Renewal Discount
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
<?php | |
/* | |
Early Renewal Discount | |
*/ | |
function erd_pmpro_checkout_level($level) | |
{ | |
//if a discount code is being used, ignore the renewal price | |
global $discount_code; | |
if(!empty($discount_code)) | |
return $level; | |
//this is an array of level ids this renewal offer is available for and the renewal cost for each | |
$discounts = array( | |
1 => 49, | |
2 => 49, | |
3 => 49, | |
4 => array( //use an array to change more than initial_payment | |
'initial_payment' => 49, | |
'expiration_number' => 1 | |
), | |
); | |
//only if you already have the level | |
if(pmpro_hasMembershipLevel($level->id) && in_array($level->id, array_keys($discounts))) | |
{ | |
//check if an array or else (number) was given | |
if(is_array($discounts[$level->id])) | |
{ | |
//adjust each value | |
foreach($discounts[$level->id] as $key => $value) | |
{ | |
$level->$key = $value; | |
} | |
} | |
else | |
{ | |
//assume the initial price is meant | |
$level->initial_payment = $discounts[$level->id]; | |
} | |
} | |
return $level; | |
} | |
add_filter('pmpro_checkout_level', 'erd_pmpro_checkout_level'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment