/**
  * If a product is being marked as not purchasable because it is limited and the customer has a subscription,
  * but the current request is to resubscribe to the subscription, then mark it as purchasable.
  *
  * @since 2.0
  * @return bool
  */
 public static function is_purchasable($is_purchasable, $product)
 {
     global $wp;
     if (!isset(self::$is_purchasable_cache[$product->id])) {
         self::$is_purchasable_cache[$product->id] = $is_purchasable;
         if (self::is_subscription($product->id) && 'no' != $product->limit_subscriptions && !wcs_is_order_received_page() && !wcs_is_paypal_api_page()) {
             if (('active' == $product->limit_subscriptions && wcs_user_has_subscription(0, $product->id, 'on-hold') || wcs_user_has_subscription(0, $product->id, $product->limit_subscriptions)) && !self::order_awaiting_payment_for_product($product->id)) {
                 self::$is_purchasable_cache[$product->id] = false;
             }
         }
     }
     return self::$is_purchasable_cache[$product->id];
 }
 /**
  * Checks if the variable product this variation belongs to is purchasable.
  *
  * @access public
  * @return bool
  */
 function is_purchasable()
 {
     $purchasable = $this->parent->is_purchasable();
     // if we have a limited subscription product, make sure the customer doesn't already have another variation for the same variable product in their cart, but only if we're not on the order received or PayPal return pages (we can't use is_order_received_page() to check that becuase get_cart_from_session() is called before the query vars are setup)
     if ('no' != $this->parent->limit_subscriptions && !empty(WC()->cart->cart_contents) && !wcs_is_order_received_page() && !wcs_is_paypal_api_page()) {
         foreach (WC()->cart->cart_contents as $cart_item) {
             // can't use WC()->cart->get_cart() because it will trigger an infinite loop when this is called within WC_Cart::get_cart_from_session()
             if ($this->id == $cart_item['data']->id && $this->variation_id != $cart_item['data']->variation_id) {
                 $purchasable = false;
                 break;
             }
         }
     }
     return apply_filters('woocommerce_subscription_variation_is_purchasable', $purchasable, $this);
 }