Automattic\WooCommerce\Internal\Admin\Orders
ListTable::count_orders_by_status()
Count orders by status.
Метод класса: ListTable{}
Хуки из метода
Возвращает
int
.
Использование
// private - только в коде основоного (родительского) класса $result = $this->count_orders_by_status( $status ): int;
- $status(строка|string[]) (обязательный)
- The order status we are interested in.
Код ListTable::count_orders_by_status() ListTable::count orders by status WC 7.5.1
private function count_orders_by_status( $status ): int { global $wpdb; // Compute all counts and cache if necessary. if ( is_null( $this->status_count_cache ) ) { $orders_table = OrdersTableDataStore::get_orders_table_name(); $res = $wpdb->get_results( $wpdb->prepare( "SELECT status, COUNT(*) AS cnt FROM {$orders_table} WHERE type = %s GROUP BY status", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared $this->order_type ), ARRAY_A ); $this->status_count_cache = $res ? array_combine( array_column( $res, 'status' ), array_map( 'absint', array_column( $res, 'cnt' ) ) ) : array(); } $status = (array) $status; $count = array_sum( array_intersect_key( $this->status_count_cache, array_flip( $status ) ) ); /** * Allows 3rd parties to modify the count of orders by status. * * @param int $count Number of orders for the given status. * @param string[] $status List of order statuses in the count. * @since 7.3.0 */ return apply_filters( 'woocommerce_' . $this->order_type . '_list_table_order_count', $count, $status ); }