Hooks::provide_customers_results_to_ajax( array $results, array $search )

Provides the results for the customers dropdown in the Orders table.


Parameters

$results

(array) (Required) The results.

$search

(array) (Required) The search.


Top ↑

Return

(array)


Top ↑

Source

File: src/Tickets/Commerce/Hooks.php

	public function provide_customers_results_to_ajax( $results, $search ) {
		if ( empty( $search['term'] ) ) {
			return $results;
		}

		$term = '*' . $search['term'] . '*';

		$args = [
			'count_total'    => false,
			'number'         => 10,
			'search'         => $term,
			'search_columns' => [ 'ID', 'user_login', 'user_email', 'user_nicename', 'display_name' ],
			'fields'         => [ 'ID', 'user_email', 'display_name' ],
		];

		$query = new WP_User_Query( $args );

		$user_results = $query->get_results();

		if ( empty( $user_results ) ) {
			return $results;
		}

		$results = array_map(
			function ( $user ) {
				return [
					'id'   => $user->ID,
					'text' => $user->display_name . ' (' . $user->user_email . ')',
				];
			},
			$user_results
		);

		return [ 'results' => $results ];
	}

Top ↑

Changelog

Changelog
Version Description
5.13.0 Introduced.