diff --git a/plugins/woocommerce/changelog/pr-46129 b/plugins/woocommerce/changelog/pr-46129 new file mode 100644 index 00000000000..a5ffeadb269 --- /dev/null +++ b/plugins/woocommerce/changelog/pr-46129 @@ -0,0 +1,4 @@ +Significance: minor +Type: update + +Add order search by transaction_id \ No newline at end of file diff --git a/plugins/woocommerce/src/Internal/DataStores/Orders/OrdersTableSearchQuery.php b/plugins/woocommerce/src/Internal/DataStores/Orders/OrdersTableSearchQuery.php index de3f76b8e9e..ad782ff7d49 100644 --- a/plugins/woocommerce/src/Internal/DataStores/Orders/OrdersTableSearchQuery.php +++ b/plugins/woocommerce/src/Internal/DataStores/Orders/OrdersTableSearchQuery.php @@ -54,6 +54,7 @@ class OrdersTableSearchQuery { private function sanitize_search_filters( string $search_filter ) : array { $core_filters = array( 'order_id', + 'transaction_id', 'customer_email', 'customers', // customers also searches in meta. 'products', @@ -199,6 +200,13 @@ class OrdersTableSearchQuery { ); } + if ( 'transaction_id' === $search_filter ) { + return $wpdb->prepare( + "`$order_table`.transaction_id LIKE %s", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- $order_table is hardcoded. + '%' . $wpdb->esc_like( $this->search_term ) . '%' + ); + } + if ( 'products' === $search_filter ) { return $wpdb->prepare( 'search_query_items.order_item_name LIKE %s',