Automattic\WooCommerce\Internal\DataStores\Orders
OrdersTableQuery::map_gmt_and_post_keys_to_hpos_keys()
Helper function to map posts and gmt based keys to HPOS keys.
Method of the class: OrdersTableQuery{}
No Hooks.
Return
Array|Mixed
. Date query argument with modified keys.
Usage
// private - for code of main (parent) class only $result = $this->map_gmt_and_post_keys_to_hpos_keys( $query );
- $query(array) (required)
- Date query argument.
OrdersTableQuery::map_gmt_and_post_keys_to_hpos_keys() OrdersTableQuery::map gmt and post keys to hpos keys code WC 9.3.3
private function map_gmt_and_post_keys_to_hpos_keys( $query ) { if ( ! is_array( $query ) ) { return $query; } $post_to_hpos_mappings = array( 'post_date' => 'date_created', 'post_date_gmt' => 'date_created_gmt', 'post_modified' => 'date_updated', 'post_modified_gmt' => 'date_updated_gmt', '_date_completed' => 'date_completed', '_date_paid' => 'date_paid', 'date_modified' => 'date_updated', 'date_modified_gmt' => 'date_updated_gmt', ); $local_to_gmt_date_keys = array( 'date_created' => 'date_created_gmt', 'date_updated' => 'date_updated_gmt', 'date_paid' => 'date_paid_gmt', 'date_completed' => 'date_completed_gmt', ); array_walk( $query, function ( &$sub_query ) { $sub_query = $this->map_gmt_and_post_keys_to_hpos_keys( $sub_query ); } ); if ( ! isset( $query['column'] ) ) { return $query; } if ( isset( $post_to_hpos_mappings[ $query['column'] ] ) ) { $query['column'] = $post_to_hpos_mappings[ $query['column'] ]; } // Convert any local dates to GMT. if ( isset( $local_to_gmt_date_keys[ $query['column'] ] ) ) { $query['column'] = $local_to_gmt_date_keys[ $query['column'] ]; $op = isset( $query['after'] ) ? 'after' : 'before'; $date_value_local = $query[ $op ]; $date_value_gmt = wc_string_to_timestamp( get_gmt_from_date( wc_string_to_datetime( $date_value_local ) ) ); $query[ $op ] = $this->date_to_date_query_arg( $date_value_gmt ); } return $query; }