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

Automattic\WooCommerce\Admin\API\Reports

Segmenter::merge_segment_intervals_results() protected WC 1.0

Merges segmented results for intervals response part.

E.g. $r1 = array(

0 => array(
	 'product_id'    => 3,
	 'time_interval' => '2018-12'
	 'net_amount'    => 15,
),

); $r2 = array(

0 => array(
	 'product_id'      => 3,
	 'time_interval' => '2018-12'
	 'avg_order_value' => 25,
),

);

$merged = array(

'2018-12' => array(
	 'segments' => array(
		 3 => array(
			 'segment_id' => 3,
			 'subtotals'  => array(
				 'net_amount'      => 15,
				 'avg_order_value' => 25,
			 ),
		 ),
	 ),
),

);

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

Хуков нет.

Возвращает

Массив.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->merge_segment_intervals_results( $segment_dimension, $result1, $result2 );
$segment_dimension(строка) (обязательный)
Name of the segment dimension=key in the result arrays used to match records from result sets.
$result1(массив) (обязательный)
Array 1 of segmented figures.
$result2(массив) (обязательный)
Array 2 of segmented figures.

Код Segmenter::merge_segment_intervals_results() WC 5.5.2

<?php
protected function merge_segment_intervals_results( $segment_dimension, $result1, $result2 ) {
	$result_segments = array();
	$segment_labels  = $this->get_segment_labels();

	foreach ( $result1 as $segment_data ) {
		$segment_id = $segment_data[ $segment_dimension ];
		if ( ! isset( $segment_labels[ $segment_id ] ) ) {
			continue;
		}

		$time_interval = $segment_data['time_interval'];
		if ( ! isset( $result_segments[ $time_interval ] ) ) {
			$result_segments[ $time_interval ]             = array();
			$result_segments[ $time_interval ]['segments'] = array();
		}

		unset( $segment_data['time_interval'] );
		unset( $segment_data['datetime_anchor'] );
		unset( $segment_data[ $segment_dimension ] );
		$segment_datum = array(
			'segment_label' => $segment_labels[ $segment_id ],
			'segment_id'    => $segment_id,
			'subtotals'     => $segment_data,
		);
		$result_segments[ $time_interval ]['segments'][ $segment_id ] = $segment_datum;
	}

	foreach ( $result2 as $segment_data ) {
		$segment_id = $segment_data[ $segment_dimension ];
		if ( ! isset( $segment_labels[ $segment_id ] ) ) {
			continue;
		}

		$time_interval = $segment_data['time_interval'];
		if ( ! isset( $result_segments[ $time_interval ] ) ) {
			$result_segments[ $time_interval ]             = array();
			$result_segments[ $time_interval ]['segments'] = array();
		}

		unset( $segment_data['time_interval'] );
		unset( $segment_data['datetime_anchor'] );
		unset( $segment_data[ $segment_dimension ] );

		if ( ! isset( $result_segments[ $time_interval ]['segments'][ $segment_id ] ) ) {
			$result_segments[ $time_interval ]['segments'][ $segment_id ] = array(
				'segment_label' => $segment_labels[ $segment_id ],
				'segment_id'    => $segment_id,
				'subtotals'     => array(),
			);
		}
		$result_segments[ $time_interval ]['segments'][ $segment_id ]['subtotals'] = array_merge( $result_segments[ $time_interval ]['segments'][ $segment_id ]['subtotals'], $segment_data );
	}
	return $result_segments;
}