WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru Платформа для конвертации и монетизации трафика
функция не описана

Automattic\WooCommerce\Blocks\StoreApi\Routes

CartUpdateCustomer::prepare_address_fields() protected WC 1.0

Format provided address fields.

{} Это метод класса: CartUpdateCustomer{}

Хуков нет.

Возвращает

Массив.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->prepare_address_fields( $address, $allowed_countries );
$address(массив) (обязательный)
Address fields.
$allowed_countries(массив) (обязательный)
Countries that must be used.

Код CartUpdateCustomer::prepare_address_fields() WC 5.0.0

<?php
protected function prepare_address_fields( $address, $allowed_countries ) {
	// Addresses require a country, otherwise they are not valid. This returns an empty address. There is no address
	// validation in this case because we do not want to block updates of other data such as email address.
	if ( empty( $address['country'] ) ) {
		return [];
	}

	$address['country'] = wc_strtoupper( $address['country'] );

	if (
		is_array( $allowed_countries ) &&
		count( $allowed_countries ) > 0 &&
		! array_key_exists( $address['country'], $allowed_countries )
	) {
		throw new RouteException(
			'woocommerce_rest_cart_invalid_country',
			sprintf(
				/* translators: 1: valid country codes */
				__( 'Address country is not valid. Please provide one of the following: %s', 'woocommerce' ),
				implode( ', ', array_keys( $allowed_countries ) )
			),
			400
		);
	}

	$address['postcode'] = isset( $address['postcode'] ) ? wc_format_postcode( $address['postcode'], $address['country'] ) : null;

	if ( ! empty( $address['state'] ) ) {
		$valid_states = wc()->countries->get_states( $address['country'] );

		if ( is_array( $valid_states ) && count( $valid_states ) > 0 ) {
			$valid_state_values = array_map( 'wc_strtoupper', array_flip( array_map( 'wc_strtoupper', $valid_states ) ) );
			$address['state']   = wc_strtoupper( $address['state'] );

			if ( isset( $valid_state_values[ $address['state'] ] ) ) {
				// With this part we consider state value to be valid as well,
				// convert it to the state key for the valid_states check below.
				$address['state'] = $valid_state_values[ $address['state'] ];
			}

			if ( ! in_array( $address['state'], $valid_state_values, true ) ) {
				throw new RouteException(
					'woocommerce_rest_cart_invalid_state',
					sprintf(
						/* translators: 1: valid states */
						__( 'Address state is not valid. Please enter one of the following: %s', 'woocommerce' ),
						implode( ', ', $valid_states )
					),
					400
				);
			}
		}
	}

	return $address;
}