Forked from strangerstudios/pmpro_level_groups.php
Last active
August 29, 2015 14:18
-
-
Save messica/d3b8e84013960eb40c32 to your computer and use it in GitHub Desktop.
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
/* | |
Show payment options (as levels) at checkout. | |
*/ | |
// Define groups of levels. array(1,2) means that levels 1 and 2 are in a group and options will be shown for both levels at checkout for those levels. | |
global $pmpro_level_groups; | |
$pmpro_level_groups = array(array(1,2)); | |
//show options at checkout | |
function pmprogl_pmpro_checkout_boxes() | |
{ | |
global $pmpro_level_groups, $pmpro_level, $discount_code, $wpdb; | |
//no groups? return | |
if(empty($pmpro_level_groups) || empty($pmpro_level)) | |
return; | |
//get id for discount code | |
if(!empty($discount_code)) | |
$discount_code_id = $wpdb->get_var("SELECT id FROM $wpdb->pmpro_discount_codes WHERE code = '" . $discount_code . "' LIMIT 1"); | |
//get first group this level is in | |
foreach($pmpro_level_groups as $group) | |
{ | |
if(in_array($pmpro_level->id, $group)) | |
{ | |
//show options for these levels | |
?> | |
<table id="pmpro_level_options" class="pmpro_checkout top1em" width="100%" cellpadding="0" cellspacing="0" border="0"> | |
<thead> | |
<tr> | |
<th>Select a payment plan.</th> | |
</tr> | |
</thead> | |
<tbody> | |
<tr> | |
<td> | |
<div> | |
<?php | |
foreach($group as $level_id) | |
{ | |
$level = pmpro_getLevel($level_id); | |
//apply discount code | |
if(!empty($discount_code)) | |
{ | |
$code_check = pmpro_checkDiscountCode($discount_code, $level_id, true); | |
if ($code_check[0] == false) { | |
//doesn't apply to this level | |
} else { | |
$sqlQuery = "SELECT l.id, cl.*, l.name, l.description, l.allow_signups FROM $wpdb->pmpro_discount_codes_levels cl LEFT JOIN $wpdb->pmpro_membership_levels l ON cl.level_id = l.id LEFT JOIN $wpdb->pmpro_discount_codes dc ON dc.id = cl.code_id WHERE dc.code = '" . $discount_code . "' AND cl.level_id = '" . (int)$_REQUEST['level'] . "' LIMIT 1"; | |
$level = $wpdb->get_row($sqlQuery); | |
//if the discount code doesn't adjust the level, let's just get the straight level | |
if (empty($level)) | |
$level = $wpdb->get_row("SELECT * FROM $wpdb->pmpro_membership_levels WHERE id = '" . $level_id . "'"); | |
//filter adjustments to the level | |
$level->code_id = $discount_code_id; | |
$level = apply_filters("pmpro_discount_code_level", $level, $discount_code_id); | |
} | |
} | |
//apply filters | |
$level = apply_filters("pmpro_checkout_level", $level); | |
?> | |
<input type="radio" id="pmpro_level_<?php echo $level_id;?>" name="level" value="<?php echo $level_id;?>" <?php checked($pmpro_level->id, $level_id);?>> | |
<label class="pmpro_normal" for="pmpro_level_<?php echo $level_id;?>" /><?php echo pmpro_getLevelCost($level, false, true);?></label> | |
| |
<?php | |
} | |
?> | |
</div> | |
</td> | |
</tr> | |
</tbody> | |
</table> | |
<?php | |
} | |
} | |
} | |
add_action('pmpro_checkout_boxes', 'pmprogl_pmpro_checkout_boxes'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment