Skip to content

Instantly share code, notes, and snippets.

@ideadude
Last active September 15, 2021 19:47
Show Gist options
  • Save ideadude/f437065fe9d3ff196266bd9839b431ce to your computer and use it in GitHub Desktop.
Save ideadude/f437065fe9d3ff196266bd9839b431ce to your computer and use it in GitHub Desktop.
Custom pricing logic we had running on our site to support legacy prices and sales.
<?php
// This is an excerpt from *some of* the custom pricing logic we had running on our site to support legacy prices and sales.
// Our current custom pricing script is about 140 lines long.
/*
If purchasing PMPro Plus and they've had plus or core in the past,
calculate the appropriate price.
*/
if($level->id == 20 && is_user_logged_in()) {
// If the user has a current subscription, use the billing amount on file.
$user_level = pmpro_getMembershipLevelForUser();
if( pmpro_hasMembershipLevel( 20 ) && pmpro_isLevelRecurring( $user_level ) ) {
$level->initial_payment = $user_level->billing_amount;
$level->billing_amount = $user_level->billing_amount;
} else {
// Check if they had a discount in the past.
$paid_47 = $wpdb->get_var("SELECT id FROM $wpdb->pmpro_membership_orders WHERE user_id = {$current_user->ID} AND membership_id IN(6,20) AND total IN('47', '47.00') AND status NOT IN('refunded', 'token', 'error', 'review') AND timestamp < '2017-08-30 00:00:00' LIMIT 1");
if($paid_47) {
$level->initial_payment = '47.00';
$level->billing_amount = '47.00';
return $level;
}
$paid_97 = $wpdb->get_var("SELECT id FROM $wpdb->pmpro_membership_orders WHERE user_id = {$current_user->ID} AND membership_id IN(6,20) AND total IN('97', '97.00') AND status NOT IN('refunded', 'token', 'error', 'review') AND timestamp < '2014-08-30 00:00:00' LIMIT 1");
$paid_147 = $wpdb->get_var("SELECT id FROM $wpdb->pmpro_membership_orders WHERE user_id = {$current_user->ID} AND membership_id IN(6,20) AND total IN('147', '147.00') AND status NOT IN('refunded', 'token', 'error', 'review') AND timestamp < '2017-08-30 00:00:00' LIMIT 1");
$paid_197 = $wpdb->get_var("SELECT id FROM $wpdb->pmpro_membership_orders WHERE user_id = {$current_user->ID} AND membership_id IN(6,20) AND total IN('197', '197.00') AND status NOT IN('refunded', 'token', 'error', 'review') AND timestamp < '2017-08-30 00:00:00' LIMIT 1");
if($paid_97 || $paid_147 || $paid_197) {
$level->initial_payment = '147.00';
$level->billing_amount = '147.00';
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment