Automattic\WooCommerce\Admin\API\Reports\Customers
DataStore::normalize_order_by_clause
Maps ordering specified by the user to columns in the database/fields in the data.
Handles both order_by and direction.
Method of the class: DataStore{}
No Hooks.
Returns
String.
Usage
// protected - for code of main (parent) or child class $result = $this->normalize_order_by_clause( $order_by, $order );
- $order_by(string) (required)
- Sorting criterion.
- $order(string)
- Order direction.
Default:'desc'
Changelog
| Since 10.5.0 | Introduced. |
DataStore::normalize_order_by_clause() DataStore::normalize order by clause code WC 10.5.0
protected function normalize_order_by_clause( $order_by, $order = 'desc' ) {
$order_by = esc_sql( $order_by );
$order = strtolower( $order ) === 'asc' ? 'ASC' : 'DESC';
$order_by_clause = '';
if ( 'location' === $order_by ) {
$order_by_clause = "state {$order}, country {$order}";
} else {
$order_by_clause = "{$order_by} {$order}";
}
return $order_by_clause;
}