Automattic\WooCommerce\Internal\DataStores\StockNotifications

StockNotificationsDataStore::count_by_status │ public │ WC 1.0

Count the notifications of each status.

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

Хуков нет.

Возвращает

array<string, int>. Map of status to the number of notifications in it.

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

$StockNotificationsDataStore = new StockNotificationsDataStore();
$StockNotificationsDataStore->count_by_status(): array;

Код StockNotificationsDataStore::count_by_status() WC 11.2.2

public function count_by_status(): array {
	global $wpdb;

	$table = $this->get_table_name();

	$results = $wpdb->get_results(
		"SELECT status, COUNT(id) AS total FROM $table GROUP BY status", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
		ARRAY_A
	);

	$counts = array();
	foreach ( (array) $results as $result ) {
		$counts[ (string) $result['status'] ] = (int) $result['total'];
	}

	return $counts;
}