WC_Helper::get_product_subscription_state()public staticWC 1.0

Get subscription state of a given product ID.

Method of the class: WC_Helper{}

No Hooks.

Return

Array. Array of state_name => (bool) state

Usage

$result = WC_Helper::get_product_subscription_state( $product_id );
$product_id(int) (required)
The product id.

Changelog

Since TBD

WC_Helper::get_product_subscription_state() code WC 9.3.1

public static function get_product_subscription_state( $product_id ) {
	$product_subscriptions = wp_list_filter( self::get_installed_subscriptions(), array( 'product_id' => $product_id ) );

	$subscription = ! empty( $product_subscriptions )
		? array_shift( $product_subscriptions )
		: array();

	return array(
		'unregistered' => empty( $subscription ),
		'expired'      => ( isset( $subscription['expired'] ) && $subscription['expired'] ),
		'expiring'     => ( isset( $subscription['expiring'] ) && $subscription['expiring'] ),
		'key'          => $subscription['product_key'] ?? '',
		'order_id'     => $subscription['order_id'] ?? '',
	);
}