Automattic\WooCommerce\Internal\Admin\Orders

ListTable::search_filter()privateWC 1.0

Renders the search filter dropdown.

Method of the class: ListTable{}

Return

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->search_filter();

ListTable::search_filter() code WC 9.4.2

<?php
private function search_filter() {
	$options = array(
		'order_id'       => __( 'Order ID', 'woocommerce' ),
		'customer_email' => __( 'Customer Email', 'woocommerce' ),
		'customers'      => __( 'Customers', 'woocommerce' ),
		'products'       => __( 'Products', 'woocommerce' ),
		'all'            => __( 'All', 'woocommerce' ),
	);

	/**
	 * Filters the search filters available in the admin order search. Can be used to add new or remove existing filters.
	 * When adding new filters, `woocommerce_hpos_generate_where_for_search_filter` should also be used to generate the WHERE clause for the new filter
	 *
	 * @since 8.9.0.
	 *
	 * @param $options array List of available filters.
	 */
	$options       = apply_filters( 'woocommerce_hpos_admin_search_filters', $options );
	$saved_setting = get_user_setting( 'wc-search-filter-hpos-admin', 'all' );
	$selected      = sanitize_text_field( wp_unslash( $_REQUEST['search-filter'] ?? $saved_setting ) );
	if ( $saved_setting !== $selected ) {
		set_user_setting( 'wc-search-filter-hpos-admin', $selected );
	}
	?>
	<select name="search-filter" id="order-search-filter">
		<?php foreach ( $options as $value => $label ) { ?>
			<option value="<?php echo esc_attr( wp_unslash( sanitize_text_field( $value ) ) ); ?>" <?php selected( $value, sanitize_text_field( wp_unslash( $selected ) ) ); ?>><?php echo esc_html( $label ); ?></option>
			<?php
		}
}