Created
February 14, 2018 19:36
-
-
Save ideadude/11396e8472a711357ed7d4b8b0690312 to your computer and use it in GitHub Desktop.
Make sure first period discounts set via the initial payment value can only be used once in Paid Memberships Pro
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
/** | |
* Make sure first period discounts can only be used once. | |
* | |
* If a user already checked out for another level in this group, | |
* set the initial payment to match the billing amount. | |
* | |
* Edit the array of level_ids below and then add this code into a custom plugin. | |
*/ | |
function pmpro_checkout_level_initial_payments_once($level) { | |
if( !is_user_logged_in() ) { | |
return $level; | |
} | |
global $current_user, $wpdb; | |
$level_ids = array(1,2,3,4,5,6,7,8); //need to add the id of each level this should apply to here | |
$sqlQuery = "SELECT id FROM $wpdb->pmpro_membership_orders WHERE user_id = '" . esc_sql($current_user->ID) . "' AND membership_id IN('" . implode("', '", $level_ids) . "') AND status NOT IN('refunded', 'review', 'token', 'error') LIMIT 1"; | |
$old_order_id = $wpdb->get_var($sqlQuery); | |
if( !empty( $old_order_id ) && !empty((float)$level->billing_amount) ) { | |
$level->initial_payment = $level->billing_amount; | |
} | |
return $level; | |
} | |
add_filter('pmpro_checkout_level', 'pmpro_checkout_level_initial_payments_once', 5); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment