Automattic\WooCommerce\Internal\Admin\Orders

ListTable::customers_filter()publicWC 1.0

Render the customer filter dropdown.

Method of the class: ListTable{}

No Hooks.

Return

null. Nothing.

Usage

$ListTable = new ListTable();
$ListTable->customers_filter();

ListTable::customers_filter() code WC 7.1.0

<?php
public function customers_filter() {
	$user_string = '';
	$user_id     = '';

	// phpcs:disable WordPress.Security.NonceVerification.Recommended
	if ( ! empty( $_GET['_customer_user'] ) ) {
		$user_id = absint( $_GET['_customer_user'] );
		$user    = get_user_by( 'id', $user_id );

		$user_string = sprintf(
			/* translators: 1: user display name 2: user ID 3: user email */
			esc_html__( '%1$s (#%2$s &ndash; %3$s)', 'woocommerce' ),
			$user->display_name,
			absint( $user->ID ),
			$user->user_email
		);
	}

	// Note: use of htmlspecialchars (below) is to prevent XSS when rendered by selectWoo.
	?>
	<select class="wc-customer-search" name="_customer_user" data-placeholder="<?php esc_attr_e( 'Filter by registered customer', 'woocommerce' ); ?>" data-allow_clear="true">
		<option value="<?php echo esc_attr( $user_id ); ?>" selected="selected"><?php echo htmlspecialchars( wp_kses_post( $user_string ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></option>
	</select>
	<?php
}