WC_Helper_Updater::get_updates_count()public staticWC 1.0

Get the number of products that have updates.

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

Хуков нет.

Возвращает

int. The number of products with updates.

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

$result = WC_Helper_Updater::get_updates_count();

Код WC_Helper_Updater::get_updates_count() WC 9.4.2

public static function get_updates_count() {
	$cache_key = '_woocommerce_helper_updates_count';
	$count     = get_transient( $cache_key );
	if ( false !== $count ) {
		return $count;
	}

	// Don't fetch any new data since this function in high-frequency.
	if ( ! get_transient( '_woocommerce_helper_subscriptions' ) ) {
		return 0;
	}

	if ( ! get_transient( '_woocommerce_helper_updates' ) ) {
		return 0;
	}

	$count       = 0;
	$update_data = self::get_update_data();

	if ( empty( $update_data ) ) {
		set_transient( $cache_key, $count, 12 * HOUR_IN_SECONDS );
		return $count;
	}

	// Scan local plugins.
	foreach ( WC_Helper::get_local_woo_plugins() as $plugin ) {
		if ( empty( $update_data[ $plugin['_product_id'] ] ) ) {
			continue;
		}

		if ( version_compare( $plugin['Version'], $update_data[ $plugin['_product_id'] ]['version'], '<' ) ) {
			++$count;
		}
	}

	// Scan local themes.
	foreach ( WC_Helper::get_local_woo_themes() as $theme ) {
		if ( empty( $update_data[ $theme['_product_id'] ] ) ) {
			continue;
		}

		if ( version_compare( $theme['Version'], $update_data[ $theme['_product_id'] ]['version'], '<' ) ) {
			++$count;
		}
	}

	set_transient( $cache_key, $count, 12 * HOUR_IN_SECONDS );

	return $count;
}