WC_Helper::is_subscription_installed()
Check if product relating to a subscription is installed. This method will return true if the product is installed, but will exclude subscriptions for the same product that are not in use. If a product is installed and inactive, this will ensure that one subscription is marked as installed.
Метод класса: WC_Helper{}
Хуков нет.
Возвращает
true|false
. True if installed, false otherwise.
Использование
$result = WC_Helper::is_subscription_installed( $subscription, $subscriptions );
- $subscription(массив) (обязательный)
- The subscription we're checking.
- $subscriptions(массив) (обязательный)
- The list of all the user's subscriptions.
Код WC_Helper::is_subscription_installed() WC Helper::is subscription installed WC 9.4.2
public static function is_subscription_installed( $subscription, $subscriptions ) { if ( false === $subscription['local']['installed'] ) { return false; } // If the subscription is active, then it's installed. if ( true === $subscription['active'] ) { return true; } $product_subscriptions = wp_list_filter( $subscriptions, array( 'product_id' => $subscription['product_id'], ) ); if ( empty( $product_subscriptions ) ) { return false; } // If there are no other subscriptions for this product, then it's installed. if ( 1 === count( $product_subscriptions ) ) { return true; } $active_subscription = wp_list_filter( $product_subscriptions, array( 'active' => true, ) ); // If there is another active subscription, this subscription is not installed. // If the current subscription is active, it would already return true above. if ( ! empty( $active_subscription ) ) { return false; } // Find subscriptions that can be activated. $product_subscriptions_without_maxed_connections = wp_list_filter( $product_subscriptions, array( 'maxed' => false, ) ); if ( 0 < count( $product_subscriptions_without_maxed_connections ) ) { // Pick the first subscription available for activation. $product_subscription = array_shift( $product_subscriptions_without_maxed_connections ); } else { // If there are multiple subscriptions, but no active subscriptions, then mark the first one as installed. $product_subscription = array_shift( $product_subscriptions ); } if ( $product_subscription['product_key'] === $subscription['product_key'] ) { return true; } return false; }