From bfed1d5e3ac73506d8e891da137781702c55d5b5 Mon Sep 17 00:00:00 2001 From: David Parker Date: Tue, 20 Feb 2024 11:51:01 -0500 Subject: [PATCH] Only guess for active subs --- classes/class-pmpro-subscription.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/classes/class-pmpro-subscription.php b/classes/class-pmpro-subscription.php index 6f62b58dba..fbd12e5452 100644 --- a/classes/class-pmpro-subscription.php +++ b/classes/class-pmpro-subscription.php @@ -1247,16 +1247,18 @@ private function maybe_fix_default_migration_data() { * created for. * 4. If we do not find a membership level that matches the subscription level and is recurring, * then let's use the default membership level settings if it is recurring. - */ - $all_user_levels = pmpro_getMembershipLevelsForUser( $this->user_id, true ); // True to include old memberships. - // Looping through $all_user_levels backwards to get the most recent first. - for ( end( $all_user_levels ); key( $all_user_levels ) !== null; prev( $all_user_levels ) ) { - $level_check = current( $all_user_levels ); - - // Let's check if level the same level as this subscription and if it's a recurring level. - if ( $level_check->id == $this->membership_level_id && ! empty( $level_check->billing_amount ) && ! empty( $level_check->cycle_number ) ) { - $subscription_level = $level_check; - break; + */ + if ( 'active' === $this->status ) { // Only guess for active subscriptions. For cancelled subscriptions, we would rather show $0/month than a potentially wrong amount. + $all_user_levels = pmpro_getMembershipLevelsForUser( $this->user_id, true ); // True to include old memberships. + // Looping through $all_user_levels backwards to get the most recent first. + for ( end( $all_user_levels ); key( $all_user_levels ) !== null; prev( $all_user_levels ) ) { + $level_check = current( $all_user_levels ); + + // Let's check if level the same level as this subscription and if it's a recurring level. + if ( $level_check->id == $this->membership_level_id && ! empty( $level_check->billing_amount ) && ! empty( $level_check->cycle_number ) ) { + $subscription_level = $level_check; + break; + } } }