Automattic\WooCommerce\Internal\DataStores\Orders

OrdersTableSearchQuery::generate_where_for_search_filter()privateWC 1.0

Generates WHERE clause for a given search filter. Right now we only have the products and customers filters that actually use WHERE, but in the future we may add more -- for example, custom order fields, payment tokens and so on. This function makes it easier to add more filters in the future.

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

Возвращает

Строку. WHERE clause.

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

// private - только в коде основоного (родительского) класса
$result = $this->generate_where_for_search_filter( $search_filter ): string;
$search_filter(строка) (обязательный)
Name of the search filter.

Код OrdersTableSearchQuery::generate_where_for_search_filter() WC 9.7.1

private function generate_where_for_search_filter( string $search_filter ): string {
	global $wpdb;

	$order_table = $this->query->get_table_name( 'orders' );

	if ( 'customer_email' === $search_filter ) {
		return $wpdb->prepare(
			"`$order_table`.billing_email LIKE %s", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- $order_table is hardcoded.
			$wpdb->esc_like( $this->search_term ) . '%'
		);
	}

	if ( 'order_id' === $search_filter && is_numeric( $this->search_term ) ) {
		return $wpdb->prepare(
			"`$order_table`.id = %d", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- $order_table is hardcoded.
			absint( $this->search_term )
		);
	}

	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 $this->get_where_for_products();
	}

	if ( 'customers' === $search_filter ) {
		return $this->get_where_for_customers();
	}

	/**
	 * Filter to support adding a custom order search filter.
	 * Provide a WHERE clause for a custom search filter via this filter. This should be used with the
	 * `woocommerce_hpos_admin_search_filters` to declare a new custom filter, and optionally also with the
	 * `woocommerce_hpos_generate_join_for_search_filter` filter if a join is also needed.
	 *
	 * Hardcoded filters (products, customers, ID and email) cannot be modified using this filter for consistency.
	 *
	 * @since 8.9.0
	 *
	 * @param string $where WHERE clause to add to the search query.
	 * @param string $search_term The search term.
	 * @param string $search_filter Name of the search filter. Use this to bail early if this is not the filter you are looking for.
	 * @param OrdersTableQuery $query The order query object.
	 */
	return apply_filters(
		'woocommerce_hpos_generate_where_for_search_filter',
		'',
		$this->search_term,
		$search_filter,
		$this->query
	);
}