Automattic\WooCommerce\Internal\DataStores\Orders

OrdersTableQuery::get_core_mapping_join()publicWC 7.0.0

Returns an SQL JOIN clause that can be used to join the main orders table with another order table.

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

Хуков нет.

Возвращает

Строку. The JOIN clause.

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

$OrdersTableQuery = new OrdersTableQuery();
$OrdersTableQuery->get_core_mapping_join( $mapping_id ): string;
$mapping_id(строка) (обязательный)
The mapping name (e.g. 'orders' or 'operational_data').

Список изменений

С версии 7.0.0 Введена.

Код OrdersTableQuery::get_core_mapping_join() WC 9.4.2

public function get_core_mapping_join( string $mapping_id ): string {
	global $wpdb;

	if ( 'orders' === $mapping_id ) {
		return '';
	}

	$is_address_mapping = in_array( $mapping_id, array( 'billing_address', 'shipping_address' ), true );

	$alias   = $this->get_core_mapping_alias( $mapping_id );
	$table   = $is_address_mapping ? $this->tables['addresses'] : $this->tables[ $mapping_id ];
	$join    = '';
	$join_on = '';

	$join .= "INNER JOIN `{$table}`" . ( $alias !== $table ? " AS `{$alias}`" : '' );

	if ( isset( $this->mappings[ $mapping_id ]['order_id'] ) ) {
		$join_on .= "`{$this->tables['orders']}`.id = `{$alias}`.order_id";
	}

	if ( $is_address_mapping ) {
		$join_on .= $wpdb->prepare( " AND `{$alias}`.address_type = %s", substr( $mapping_id, 0, -8 ) ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
	}

	return $join . ( $join_on ? " ON ( {$join_on} )" : '' );
}