Automattic\WooCommerce\Internal\DataStores\Orders

OrdersTableMetaQuery::flatten_where_clauses()privateWC 1.0

Flattens a nested WHERE array.

{} It's a method of the class: OrdersTableMetaQuery{}

No Hooks.

Return

String. An SQL WHERE clause.

Usage

// private - for code of main (parent) class only
$result = $this->flatten_where_clauses( $where ): string;
$where(array) (required)
A possibly nested WHERE array with AND/OR operators.

Code of OrdersTableMetaQuery::flatten_where_clauses() WC 7.1.0

private function flatten_where_clauses( $where ): string {
	if ( is_string( $where ) ) {
		return trim( $where );
	}

	$chunks   = array();
	$operator = $this->sanitize_relation( $where['operator'] ?? '' );

	foreach ( $where as $key => $w ) {
		if ( 'operator' === $key ) {
			continue;
		}

		$flattened = $this->flatten_where_clauses( $w );
		if ( $flattened ) {
			$chunks[] = $flattened;
		}
	}

	if ( $chunks ) {
		return '(' . implode( " {$operator} ", $chunks ) . ')';
	} else {
		return '';
	}
}