Automattic\WooCommerce\Internal\DataStores\Orders

OrdersTableMetaQuery::generate_join_for_clause()privateWC 1.0

Generates a JOIN clause to handle an atomic meta_query clause.

{} It's a method of the class: OrdersTableMetaQuery{}

No Hooks.

Return

String. An SQL JOIN clause.

Usage

// private - for code of main (parent) class only
$result = $this->generate_join_for_clause( $clause, $alias ): string;
$clause(array) (required)
An atomic meta_query clause.
$alias(string) (required)
Metadata table alias to use.

Code of OrdersTableMetaQuery::generate_join_for_clause() WC 7.1.0

private function generate_join_for_clause( array $clause, string $alias ): string {
	global $wpdb;

	if ( 'NOT EXISTS' === $clause['compare'] ) {
		if ( 'LIKE' === $clause['compare_key'] ) {
			return $wpdb->prepare(
				"LEFT JOIN {$this->meta_table} AS {$alias} ON ( {$this->orders_table}.id = {$alias}.order_id AND {$alias}.meta_key LIKE %s )", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
				'%' . $wpdb->esc_like( $clause['key'] ) . '%'
			);
		} else {
			return $wpdb->prepare(
				"LEFT JOIN {$this->meta_table} AS {$alias} ON ( {$this->orders_table}.id = {$alias}.order_id AND {$alias}.meta_key = %s )", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
				$clause['key']
			);
		}
	}

	return "INNER JOIN {$this->meta_table} AS {$alias} ON ( {$this->orders_table}.id = {$alias}.order_id )";
}