Automattic\WooCommerce\Internal\DataStores\Orders

OrdersTableQuery::get_field_mapping_info()publicWC 1.0

Finds table and mapping information about a field or column.

Method of the class: OrdersTableQuery{}

No Hooks.

Return

false|Array.

Usage

$OrdersTableQuery = new OrdersTableQuery();
$OrdersTableQuery->get_field_mapping_info( $field );
$field(string) (required)
Field to look for in <mapping|field_name>.<column|field_name> format or just <field_name>.

OrdersTableQuery::get_field_mapping_info() code WC 7.1.0

public function get_field_mapping_info( $field ) {
	global $wpdb;

	$result = array(
		'table'       => '',
		'mapping_id'  => '',
		'field_name'  => '',
		'column'      => '',
		'column_type' => '',
	);

	$mappings_to_search = array();

	if ( false !== strstr( $field, '.' ) ) {
		list( $mapping_or_table, $field_name_or_col ) = explode( '.', $field );

		$mapping_or_table = substr( $mapping_or_table, 0, strlen( $wpdb->prefix ) ) === $wpdb->prefix ? substr( $mapping_or_table, strlen( $wpdb->prefix ) ) : $mapping_or_table;
		$mapping_or_table = 'wc_' === substr( $mapping_or_table, 0, 3 ) ? substr( $mapping_or_table, 3 ) : $mapping_or_table;

		if ( isset( $this->mappings[ $mapping_or_table ] ) ) {
			if ( isset( $this->mappings[ $mapping_or_table ][ $field_name_or_col ] ) ) {
				$result['mapping_id'] = $mapping_or_table;
				$result['column']     = $field_name_or_col;
			} else {
				$mappings_to_search = array( $mapping_or_table );
			}
		}
	} else {
		$field_name_or_col  = $field;
		$mappings_to_search = array_keys( $this->mappings );
	}

	foreach ( $mappings_to_search as $mapping_id ) {
		foreach ( $this->mappings[ $mapping_id ] as $column_name => $column_data ) {
			if ( isset( $column_data['name'] ) && $column_data['name'] === $field_name_or_col ) {
				$result['mapping_id'] = $mapping_id;
				$result['column']     = $column_name;
				break 2;
			}
		}
	}

	if ( ! $result['mapping_id'] || ! $result['column'] ) {
		return false;
	}

	$field_info = $this->mappings[ $result['mapping_id'] ][ $result['column'] ];

	$result['field_name']  = $field_info['name'];
	$result['column_type'] = $field_info['type'];
	$result['table']       = ( in_array( $result['mapping_id'], array( 'billing_address', 'shipping_address' ), true ) )
							? $this->tables['addresses']
							: $this->tables[ $result['mapping_id'] ];

	return $result;
}