Automattic\WooCommerce\Internal\DataStores\Orders

OrdersTableQuery::maybe_remap_args()privateWC 1.0

Remaps some legacy and WP_Query specific query vars to vars available in the customer order table scheme.

Method of the class: OrdersTableQuery{}

No Hooks.

Return

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->maybe_remap_args(): void;

OrdersTableQuery::maybe_remap_args() code WC 9.3.3

private function maybe_remap_args(): void {
	$mapping = array(
		// WP_Query legacy.
		'post_date'           => 'date_created',
		'post_date_gmt'       => 'date_created_gmt',
		'post_modified'       => 'date_updated',
		'post_modified_gmt'   => 'date_updated_gmt',
		'post_status'         => 'status',
		'_date_completed'     => 'date_completed',
		'_date_paid'          => 'date_paid',
		'paged'               => 'page',
		'post_parent'         => 'parent_order_id',
		'post_parent__in'     => 'parent_order_id',
		'post_parent__not_in' => 'parent_exclude',
		'post__not_in'        => 'exclude',
		'posts_per_page'      => 'limit',
		'p'                   => 'id',
		'post__in'            => 'id',
		'post_type'           => 'type',
		'fields'              => 'return',

		'customer_user'       => 'customer_id',
		'order_currency'      => 'currency',
		'order_version'       => 'woocommerce_version',
		'cart_discount'       => 'discount_total_amount',
		'cart_discount_tax'   => 'discount_tax_amount',
		'order_shipping'      => 'shipping_total_amount',
		'order_shipping_tax'  => 'shipping_tax_amount',
		'order_tax'           => 'tax_amount',

		// Translate from WC_Order_Query to table structure.
		'version'             => 'woocommerce_version',
		'date_modified'       => 'date_updated',
		'date_modified_gmt'   => 'date_updated_gmt',
		'discount_total'      => 'discount_total_amount',
		'discount_tax'        => 'discount_tax_amount',
		'shipping_total'      => 'shipping_total_amount',
		'shipping_tax'        => 'shipping_tax_amount',
		'cart_tax'            => 'tax_amount',
		'total'               => 'total_amount',
		'customer_ip_address' => 'ip_address',
		'customer_user_agent' => 'user_agent',
		'parent'              => 'parent_order_id',
	);

	foreach ( $mapping as $query_key => $table_field ) {
		if ( isset( $this->args[ $query_key ] ) && '' !== $this->args[ $query_key ] ) {
			$this->args[ $table_field ] = $this->args[ $query_key ];
			unset( $this->args[ $query_key ] );
		}
	}

	// meta_query.
	$this->args['meta_query'] = ( $this->arg_isset( 'meta_query' ) && is_array( $this->args['meta_query'] ) ) ? $this->args['meta_query'] : array(); // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query

	$shortcut_meta_query = array();
	foreach ( array( 'key', 'value', 'compare', 'type', 'compare_key', 'type_key' ) as $key ) {
		if ( $this->arg_isset( "meta_{$key}" ) ) {
			$shortcut_meta_query[ $key ] = $this->args[ "meta_{$key}" ];
		}
	}

	if ( ! empty( $shortcut_meta_query ) ) {
		if ( ! empty( $this->args['meta_query'] ) ) {
			$this->args['meta_query'] = array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
				'relation' => 'AND',
				$shortcut_meta_query,
				$this->args['meta_query'],
			);
		} else {
			$this->args['meta_query'] = array( $shortcut_meta_query ); // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
		}
	}
}