WC_Product_Usage::get_rules_for_product()public staticWC 9.3.0

Get product usage rule if it needs to be applied to the given product id.

Метод класса: WC_Product_Usage{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

$result = WC_Product_Usage::get_rules_for_product( $product_id ): ?WC_Product_Usage_Rule_Set;
$product_id(int) (обязательный)
product id to get feature restriction rules.

Список изменений

С версии 9.3.0 Введена.

Код WC_Product_Usage::get_rules_for_product() WC 9.4.2

public static function get_rules_for_product( int $product_id ): ?WC_Product_Usage_Rule_Set {
	$rules = self::get_product_usage_restriction_rule( $product_id );
	if ( null === $rules ) {
		return null;
	}

	// When there is no subscription for the product, restrict usage.
	if ( ! WC_Helper::has_product_subscription( $product_id ) ) {
		return new WC_Product_Usage_Rule_Set( $rules );
	}

	$subscriptions = wp_list_filter( WC_Helper::get_installed_subscriptions(), array( 'product_id' => $product_id ) );
	if ( empty( $subscriptions ) ) {
		return new WC_Product_Usage_Rule_Set( $rules );
	}

	// Product should only have a single connected subscription on current store.
	$product_subscription = current( $subscriptions );
	if ( $product_subscription['expired'] ) {
		return new WC_Product_Usage_Rule_Set( $rules );
	}

	return null;
}