Automattic\WooCommerce\Admin\API
Orders::search_partial_order_number
Helper method to allow searching by partial order number.
Method of the class: Orders{}
No Hooks.
Returns
Array. Modified args with partial order search included.
Usage
// private - for code of main (parent) class only $result = $this->search_partial_order_number( $number, $args );
- $number(int) (required)
- Partial order number match.
- $args(array) (required)
- List of arguments for the request.
Orders::search_partial_order_number() Orders::search partial order number code WC 10.3.6
private function search_partial_order_number( $number, $args ) {
global $wpdb;
$partial_number = trim( $number );
$limit = intval( $args['posts_per_page'] );
if ( OrderUtil::custom_orders_table_usage_is_enabled() ) {
$order_table_name = OrdersTableDataStore::get_orders_table_name();
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- $orders_table_name is hardcoded.
$order_ids = $wpdb->get_col(
$wpdb->prepare(
"SELECT id
FROM $order_table_name
WHERE type = 'shop_order'
AND id LIKE %s
LIMIT %d",
$wpdb->esc_like( absint( $partial_number ) ) . '%',
$limit
)
);
// phpcs:enable
} else {
$order_ids = $wpdb->get_col(
$wpdb->prepare(
"SELECT ID
FROM {$wpdb->prefix}posts
WHERE post_type = 'shop_order'
AND ID LIKE %s
LIMIT %d",
$wpdb->esc_like( absint( $partial_number ) ) . '%',
$limit
)
);
}
// Force WP_Query return empty if don't found any order.
$order_ids = empty( $order_ids ) ? array( 0 ) : $order_ids;
$args['post__in'] = $order_ids;
return $args;
}