diff --git a/ms_core/ms_products/ms_products.plans.inc b/ms_core/ms_products/ms_products.plans.inc
index 4f4411e..bda3b01 100644
--- a/ms_core/ms_products/ms_products.plans.inc
+++ b/ms_core/ms_products/ms_products.plans.inc
@@ -373,14 +373,18 @@ function ms_products_purchase_product(MsProductsPlan $plan, $checkout = FALSE, $
     }
   }
 
+
   // Let other modules restrict access to purchasing products.
   module_invoke_all('ms_products_before_added_to_cart', $account, $plan);
 
-  // If the user can upgrade to this plan, then do it.
-  if ($account->uid AND isset($account->ms_products_purchases) AND is_array($account->ms_products_purchases)) {
-    foreach ($account->ms_products_purchases as $info) {
-      $purchase = ms_products_purchase_load($info['id']);
-      $plan = ms_products_plan_load($purchase->sku);
+  // If the user can upgrade or downgrade to this plan, then do it.
+  $ms_products_purchases = ms_products_get_user_purchases($user->uid);
+  if ($ms_products_purchases) {
+    foreach ($ms_products_purchases as $purchase) {
+      if ($purchase->status != 'active') {
+        continue;
+      }
+      $previous_plan = ms_products_plan_load($purchase->sku);
       $order = ms_core_order_load($purchase->oid);
 
       // Get the product id of the purchase in the order.
@@ -391,28 +395,23 @@ function ms_products_purchase_product(MsProductsPlan $plan, $checkout = FALSE, $
         }
       }
 
-      $modify_options = ms_products_get_modify_options($plan);
-      foreach ($modify_options['upgrade'] as $u_plan) {
-        if ($u_plan->sku == $plan->sku) {
-          if (!empty($plan->data['grant_credit'])) {
-            if ($credit = ms_core_calculate_credit($purchase->oid, $purchase->expiration, $plan->recurring_schedule['main_amount'])) {
-              $data['residual_credit'] = $credit;
-              $order = ms_core_add_data($order, $data);
-            }
-          }
-          // There is an upgrade available, do it.
-          if ($product_id) {
-            drupal_goto('ms/downgrade/' . $order->oid . '/' . $plan->sku . '/' . $product_id);
-          } else {
-            drupal_goto('ms/downgrade/' . $order->oid . '/' . $plan->sku);
+      $modify_options = ms_products_get_modify_options($previous_plan);
+      if (isset($modify_options['upgrade'][$plan->sku])) {
+        // There is an upgrade available, do it.
+        if (!empty($plan->data['grant_credit'])) {
+          if ($credit = ms_core_calculate_credit($purchase->oid, $purchase->expiration, $plan->recurring_schedule['main_amount'])) {
+            $data['residual_credit'] = $credit;
+            $order = ms_core_add_data($order, $data);
           }
         }
-      }
-      foreach ($modify_options['downgrade'] as $u_plan) {
-        if ($u_plan->sku == $plan->sku) {
-          // There is a downgrade available, redirect to downgrade page.
+        if ($product_id) {
           drupal_goto(ms_core_get_modify_url($order, $plan->sku, $product_id));
+        } else {
+          drupal_goto(ms_core_get_modify_url($order, $plan->sku));
         }
+      } else if (isset($modify_options['downgrade'][$plan->sku])) {
+        // There is a downgrade available, redirect to downgrade page.
+        drupal_goto('ms/downgrade/' . $order->oid . '/' . $plan->sku);
       }
     }
   }
