Automattic\WooCommerce\Internal\DataStores\Orders
OrdersTableMetaQuery::flatten_where_clauses
Flattens a nested WHERE array.
Method of the class: OrdersTableMetaQuery{}
No Hooks.
Returns
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.
OrdersTableMetaQuery::flatten_where_clauses() OrdersTableMetaQuery::flatten where clauses code WC 10.3.3
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 '';
}
}