Automattic\WooCommerce\Internal\Admin

Analytics::get_max_order_stats_id │ private static │ WC 1.0

Highest order_id present in the order stats table (0 when empty).

Method of the class: Analytics{}

No Hooks.

Returns

int.

Usage

$result = Analytics::get_max_order_stats_id(): int;

Analytics::get_max_order_stats_id() code WC 11.3.0

private static function get_max_order_stats_id(): int {
	global $wpdb;

	// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
	$max_order_id = $wpdb->get_var( "SELECT MAX(order_id) FROM {$wpdb->prefix}wc_order_stats" );

	// Read the error before logging: the database log handler runs its own query, which clears it.
	$db_error = $wpdb->last_error;
	if ( $db_error ) {
		wc_get_logger()->error(
			sprintf( 'Highest order stats ID query failed: %s', $db_error ),
			array( 'source' => 'wc-analytics-order-import' )
		);
		throw new \Exception( $db_error ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
	}

	return intval( $max_order_id );
}