Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:strangerstudios/paid-memberships-pro…
Browse files Browse the repository at this point in the history
… into dev
  • Loading branch information
ideadude committed Jan 11, 2019
2 parents 08906f4 + 34f97bd commit b4dc7e0
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
13 changes: 10 additions & 3 deletions classes/gateways/class.pmprogateway_stripe.php
Original file line number Diff line number Diff line change
Expand Up @@ -1038,9 +1038,16 @@ static function pmpro_cron_stripe_subscription_updates()
static function pmpro_checkout_before_processing() {
global $wpdb, $current_user;

//we're only worried about cases where the user is logged in
if(!is_user_logged_in())
return;
// we're only worried about cases where the user is logged in
if( ! is_user_logged_in() ) {
return;
}

// make sure we're checking out with Stripe
$current_gateway = pmpro_getGateway();
if ( $current_gateway != 'stripe' ) {
return;
}

//check the $pmpro_cancel_previous_subscriptions filter
//this is used in add ons like Gift Memberships to stop PMPro from cancelling old memberships
Expand Down
25 changes: 25 additions & 0 deletions includes/filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,28 @@ function pmpro_pmpro_subscribe_order_startdate_limit( $order, $gateway ) {
return $order;
}
add_filter( 'pmpro_subscribe_order', 'pmpro_pmpro_subscribe_order_startdate_limit', 99, 2 );

/**
* Before changing membership at checkout,
* let's remember the order for checkout
* so we can ignore that when cancelling old orders.
*/
function pmpro_set_checkout_order_before_changing_membership_levels( $user_id, $order ) {
global $pmpro_checkout_order;
$pmpro_checkout_order = $order;
}
add_action( 'pmpro_checkout_before_change_membership_level', 'pmpro_set_checkout_order_before_changing_membership_levels', 10, 2);

/**
* Ignore the checkout order when cancelling old orders.
*/
function pmpro_ignore_checkout_order_when_cancelling_old_orders( $order_ids ) {
global $pmpro_checkout_order;

if ( ! empty( $pmpro_checkout_order ) ) {
$order_ids = array_diff( $order_ids, array( $pmpro_checkout_order->id ) );
}

return $order_ids;
}
add_filter( 'pmpro_other_order_ids_to_cancel', 'pmpro_ignore_checkout_order_when_cancelling_old_orders' );
5 changes: 5 additions & 0 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,11 @@ function pmpro_changeMembershipLevel( $level, $user_id = null, $old_level_status
);
}

/**
* Filter the other/old order ids in case we want to exclude some.
* NOTE: As of version 2.0.3, includes/filters.php has code to
* ignore the order for the current checkout.
*/
$other_order_ids = apply_filters( 'pmpro_other_order_ids_to_cancel', $other_order_ids );

// cancel any other subscriptions they have (updates pmpro_membership_orders table)
Expand Down

0 comments on commit b4dc7e0

Please sign in to comment.