/** * Checks if the store manager has requested the current product be limited to one purchase * per customer, and if so, checks whether the customer already has an active subscription to * the product. * * @access public * @return bool */ function is_purchasable() { $purchasable = parent::is_purchasable(); if (true === $purchasable && false === WC_Subscriptions_Product::is_purchasable($purchasable, $this)) { $purchasable = false; } return apply_filters('woocommerce_subscription_is_purchasable', $purchasable, $this); }
/** * 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 function is_purchasable($is_purchasable, $product) { // If the product is being set as not-purchasable by Subscriptions (due to limiting) if (false === $is_purchasable && false === WC_Subscriptions_Product::is_purchasable($is_purchasable, $product)) { // Validating when restoring cart from session if (false !== wcs_cart_contains_resubscribe()) { $is_purchasable = true; // Restoring cart from session, so need to check the cart in the session (wcs_cart_contains_renewal() only checks the cart) } elseif (isset(WC()->session->cart)) { foreach (WC()->session->cart as $cart_item_key => $cart_item) { if ($product->id == $cart_item['product_id'] && isset($cart_item[$this->cart_item_key])) { $is_purchasable = true; break; } } } elseif (isset($_GET['resubscribe'])) { // Is a request to resubscribe $subscription = wcs_get_subscription(absint($_GET['resubscribe'])); if (false !== $subscription && $subscription->has_product($product->id) && wcs_can_user_resubscribe_to($subscription)) { $is_purchasable = true; } } } return $is_purchasable; }
/** * 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 function is_purchasable($is_purchasable, $product) { // If the product is being set as not-purchasable by Subscriptions (due to limiting) if (false === $is_purchasable && false === WC_Subscriptions_Product::is_purchasable($is_purchasable, $product)) { // Adding to cart from the product page or paying for a renewal if (isset($_GET[$this->cart_item_key]) || isset($_GET['subscription_renewal']) || wcs_cart_contains_renewal()) { $is_purchasable = true; } else { if (WC()->session->cart) { foreach (WC()->session->cart as $cart_item_key => $cart_item) { if ($product->id == $cart_item['product_id'] && isset($cart_item['subscription_renewal'])) { $is_purchasable = true; break; } } } } } return $is_purchasable; }
/** * 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 function is_purchasable($is_purchasable, $product) { // If the product is being set as not-purchasable by Subscriptions (due to limiting) if (false === $is_purchasable && false === WC_Subscriptions_Product::is_purchasable($is_purchasable, $product)) { // Adding to cart from the product page if (isset($_GET[$this->cart_item_key])) { $is_purchasable = true; } } return $is_purchasable; }