Automattic\WooCommerce\Internal\DataStores\Orders

OrdersTableMetaQuery::process()privateWC 1.0

Processes meta_query entries and generates the necessary table aliases, JOIN statements and WHERE conditions.

Method of the class: OrdersTableMetaQuery{}

No Hooks.

Return

Array. A nested array of WHERE conditions.

Usage

// private - for code of main (parent) class only
$result = $this->process( $arg, $parent ): array;
$arg(array) (required)
A meta query.
$parent(null|array) (passed by reference — &)
The parent of the element being processed.
Default: null

OrdersTableMetaQuery::process() code WC 8.7.0

private function process( array &$arg, &$parent = null ): array {
	$where = array();

	if ( $this->is_atomic( $arg ) ) {
		$arg['alias'] = $this->find_or_create_table_alias_for_clause( $arg, $parent );
		$arg['cast']  = $this->sanitize_cast_type( $arg['type'] ?? '' );

		$where = array_filter(
			array(
				$this->generate_where_for_clause_key( $arg ),
				$this->generate_where_for_clause_value( $arg ),
			)
		);

		// Store clauses by their key for ORDER BY purposes.
		$flat_clause_key = is_int( $arg['index'] ) ? $arg['alias'] : $arg['index'];

		$unique_flat_key = $flat_clause_key;
		$i               = 1;
		while ( isset( $this->flattened_clauses[ $unique_flat_key ] ) ) {
			$unique_flat_key = $flat_clause_key . '-' . $i;
			$i++;
		}

		$this->flattened_clauses[ $unique_flat_key ] =& $arg;
	} else {
		// Nested.
		$relation = $arg['relation'];
		unset( $arg['relation'] );
		$chunks = array();
		foreach ( $arg as $index => &$clause ) {
			$chunks[] = $this->process( $clause, $arg );
		}

		// Merge chunks of the form OR(m) with the surrounding clause.
		if ( 1 === count( $chunks ) ) {
			$where = $chunks[0];
		} else {
			$where = array_merge(
				array(
					'operator' => $relation,
				),
				$chunks
			);
		}
	}

	return $where;
}