WC_Customer_Data_Store::search_customers()publicWC 3.0.7

Search customers and return customer IDs.

Метод класса: WC_Customer_Data_Store{}

Возвращает

Массив.

Использование

$WC_Customer_Data_Store = new WC_Customer_Data_Store();
$WC_Customer_Data_Store->search_customers( $term, $limit );
$term(строка) (обязательный)
Search term.
$limit(int|строка)
Limit search results.
По умолчанию: ''

Список изменений

С версии 3.0.7 Введена.

Код WC_Customer_Data_Store::search_customers() WC 9.4.2

public function search_customers( $term, $limit = '' ) {
	$results = apply_filters( 'woocommerce_customer_pre_search_customers', false, $term, $limit );
	if ( is_array( $results ) ) {
		return $results;
	}

	$query = new WP_User_Query(
		apply_filters(
			'woocommerce_customer_search_customers',
			array(
				'search'         => '*' . esc_attr( $term ) . '*',
				'search_columns' => array( 'user_login', 'user_url', 'user_email', 'user_nicename', 'display_name' ),
				'fields'         => 'ID',
				'number'         => $limit,
			),
			$term,
			$limit,
			'main_query'
		)
	);

	$query2 = new WP_User_Query(
		apply_filters(
			'woocommerce_customer_search_customers',
			array(
				'fields'     => 'ID',
				'number'     => $limit,
				'meta_query' => array(
					'relation' => 'OR',
					array(
						'key'     => 'first_name',
						'value'   => $term,
						'compare' => 'LIKE',
					),
					array(
						'key'     => 'last_name',
						'value'   => $term,
						'compare' => 'LIKE',
					),
				),
			),
			$term,
			$limit,
			'meta_query'
		)
	);

	$results = wp_parse_id_list( array_merge( (array) $query->get_results(), (array) $query2->get_results() ) );

	if ( $limit && count( $results ) > $limit ) {
		$results = array_slice( $results, 0, $limit );
	}

	return $results;
}