Automattic\WooCommerce\Internal\DataStores\Orders

OrdersTableQuery::generate_customer_query()privateWC 1.0

Generate SQL conditions for the 'customer' query.

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

Хуков нет.

Возвращает

Строку. SQL to be used in a WHERE clause.

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

// private - только в коде основоного (родительского) класса
$result = $this->generate_customer_query( $values, $relation ): string;
$values(массив) (обязательный)
List of customer ids or emails.
$relation(строка)
'OR' or 'AND' relation used to build the customer query.
По умолчанию: 'OR'

Код OrdersTableQuery::generate_customer_query() WC 8.7.0

private function generate_customer_query( $values, string $relation = 'OR' ): string {
	$values = is_array( $values ) ? $values : array( $values );
	$ids    = array();
	$emails = array();
	$pieces = array();
	foreach ( $values as $value ) {
		if ( is_array( $value ) ) {
			$sql      = $this->generate_customer_query( $value, 'AND' );
			$pieces[] = $sql ? '(' . $sql . ')' : '';
		} elseif ( is_numeric( $value ) ) {
			$ids[] = absint( $value );
		} elseif ( is_string( $value ) && is_email( $value ) ) {
			$emails[] = sanitize_email( $value );
		} else {
			// Invalid query.
			$pieces[] = '1=0';
		}
	}

	if ( $ids ) {
		$pieces[] = $this->where( $this->tables['orders'], 'customer_id', '=', $ids, 'int' );
	}

	if ( $emails ) {
		$pieces[] = $this->where( $this->tables['orders'], 'billing_email', '=', $emails, 'string' );
	}

	return $pieces ? implode( " $relation ", $pieces ) : '';
}