WC_Helper::get_available_subscription()
Get subscriptions for a product if it is available
Method of the class: WC_Helper{}
No Hooks.
Return
Mixed|null
.
Usage
$result = WC_Helper::get_available_subscription( $product_id );
- $product_id(string|int) (required)
- the product id to get subscriptions for.
WC_Helper::get_available_subscription() WC Helper::get available subscription code WC 9.7.1
protected static function get_available_subscription( $product_id ) { $subscriptions = self::_get_subscriptions_from_product_id( $product_id, false ); // No valid subscriptions for this product. if ( empty( $subscriptions ) ) { return null; } $subscription = null; foreach ( $subscriptions as $_sub ) { // Don't attempt to activate expired subscriptions. if ( $_sub['expired'] ) { continue; } // No more sites available in this subscription. if ( isset( $_sub['maxed'] ) && $_sub['maxed'] ) { continue; } // Looks good. $subscription = $_sub; break; } return $subscription; }