Created
December 2, 2011 05:56
-
-
Save strangerstudios/1421978 to your computer and use it in GitHub Desktop.
Paid Memberships Pro Different Payment Options at Checkout for One Level
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
/* | |
PMPro Example Offering Monthly and Annual Options on Checkout Page | |
This code assumes your levels have an annual recurring cost. | |
The first function converts your annual prices into monthly prices. | |
*/ | |
function my_getMonthlyPriceFromAnnualPrice($price) | |
{ | |
//divide by 10 and round down to nearest dollar | |
return floor($price / 10); | |
} | |
function my_pmpro_checkout_after_level_cost() | |
{ | |
global $wpdb, $pmpro_currency_symbol; | |
if(empty($_REQUEST['level'])) | |
return false; | |
//get the original level info in case it was overriden | |
$original_pmpro_level = $wpdb->get_row("SELECT * FROM $wpdb->pmpro_membership_levels WHERE id = '" . $wpdb->escape($_REQUEST['level']) . "' AND allow_signups = 1 LIMIT 1"); | |
if(empty($original_pmpro_level)) | |
return false; | |
//get the option which will be annual payment or monthly payment | |
if(!empty($_REQUEST['option'])) | |
$option = $_REQUEST['option']; | |
else | |
$option = NULL; | |
//setup a level object for the monthly version | |
$monthly_pmpro_level = wp_clone($original_pmpro_level); | |
$monthly_pmpro_level->cycle_period = "Month"; | |
$monthly_pmpro_level->billing_amount = my_getMonthlyPriceFromAnnualPrice($original_pmpro_level->billing_amount); | |
//show the option radio buttons | |
if(!empty($_REQUEST['review'])) | |
{ | |
if($option) | |
{ | |
?> | |
<input type="hidden" name="option" value="<?php echo esc_attr($option); ?>" /> | |
<?php | |
} | |
} | |
else | |
{ | |
?> | |
<div style="margin-bottom: 1em;"> | |
<p style="margin-bottom: 0;">Choose a payment plan.</p> | |
<input type="radio" name="option" value="annual" <?php if(!$option || $option == "annual") { ?>checked="checked"<?php } ?> /> | |
<?php echo $pmpro_currency_symbol; ?><?php echo round($original_pmpro_level->billing_amount); ?> Annually | |
| |
<input type="radio" name="option" value="monthly" <?php if($option == "monthly") { ?>checked="checked"<?php } ?> /> | |
<?php echo $pmpro_currency_symbol; ?><?php echo round($monthly_pmpro_level->billing_amount); ?> Monthly | |
</div> | |
<?php | |
} | |
} | |
add_action("pmpro_checkout_after_level_cost", "my_pmpro_checkout_after_level_cost"); | |
function my_pmpro_paypal_express_return_url_parameters($params) | |
{ | |
if(!empty($_REQUEST['option'])) | |
$params['option'] = $_REQUEST['option']; | |
return $params; | |
} | |
add_filter("pmpro_paypal_express_return_url_parameters", "my_pmpro_paypal_express_return_url_parameters"); | |
function my_pmpro_level_cost_text($text, $level) | |
{ | |
//blank out the text on the checkout page | |
if(!empty($_REQUEST['level'])) | |
{ | |
$text = ""; | |
} | |
return $text; | |
} | |
add_filter("pmpro_level_cost_text", "my_pmpro_level_cost_text", 10, 2); | |
function my_pmpro_checkout_level($level) | |
{ | |
//need this in case $level = false or something else | |
if(!$level->id) | |
return $level; | |
//check the option and adjust the level | |
if(!empty($_REQUEST['option'])) | |
{ | |
$option = $_REQUEST['option']; | |
if($option == "monthly") | |
{ | |
//adjust the price and billing period | |
$level->initial_payment = my_getMonthlyPriceFromAnnualPrice($level->initial_payment); | |
$level->billing_amount = my_getMonthlyPriceFromAnnualPrice($level->billing_amount); | |
$level->cycle_period = "Month"; | |
} | |
else | |
{ | |
//keep it the same | |
} | |
} | |
return $level; | |
} | |
add_filter("pmpro_checkout_level", "my_pmpro_checkout_level"); |
Any way to hide options on FREE Plans?
THIS DOES NOT WORK.
I just had a subscriber select a monthly option, the website said they were billed monthly but it took out the full year price and set them up for an annual renewal.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is so cool! Just one thing
What if you want to apply different discounts to different memeberships?