WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru Получай пассивный доход от сайта
функция не описана

WC_Tracker::get_orders_by_gateway() private WC 1.0

Get order details by gateway.

{} Это метод класса: WC_Tracker{}

Хуков нет.

Возвращает

Массив.

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

$result = WC_Tracker::get_orders_by_gateway();

Код WC_Tracker::get_orders_by_gateway() WC 5.5.2

<?php
private static function get_orders_by_gateway() {
	global $wpdb;

	$orders_by_gateway = $wpdb->get_results(
		"
		SELECT
			gateway, currency, SUM(total) AS totals, COUNT(order_id) AS counts
		FROM (
			SELECT
				orders.id AS order_id,
				MAX(CASE WHEN meta_key = '_payment_method' THEN meta_value END) gateway,
				MAX(CASE WHEN meta_key = '_order_total' THEN meta_value END) total,
				MAX(CASE WHEN meta_key = '_order_currency' THEN meta_value END) currency
			FROM
				{$wpdb->prefix}posts orders
			LEFT JOIN
				{$wpdb->prefix}postmeta order_meta ON order_meta.post_id = orders.id
			WHERE orders.post_type = 'shop_order'
				AND orders.post_status in ( 'wc-completed', 'wc-processing', 'wc-refunded' )
				AND meta_key in( '_payment_method','_order_total','_order_currency')
			GROUP BY orders.id
		) order_gateways
		GROUP BY gateway, currency
		"
	);

	$orders_by_gateway_currency = array();
	foreach ( $orders_by_gateway as $orders_details ) {
		$gateway  = 'gateway_' . $orders_details->gateway;
		$currency = $orders_details->currency;
		$count    = $gateway . '_' . $currency . '_count';
		$total    = $gateway . '_' . $currency . '_total';

		$orders_by_gateway_currency[ $count ] = $orders_details->counts;
		$orders_by_gateway_currency[ $total ] = $orders_details->totals;
	}

	return $orders_by_gateway_currency;
}