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

Automattic\WooCommerce\Blocks\StoreApi\Routes

CartUpdateShipping::validate_shipping_address() public WC 1.0

Format the request address.

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

Хуков нет.

Возвращает

\WP_REST_Response.

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

$CartUpdateShipping = new CartUpdateShipping();
$CartUpdateShipping->validate_shipping_address( $request );
$request(\WP_REST_Request) (обязательный)
Full details about the request.

Код CartUpdateShipping::validate_shipping_address() WC 4.7.0

<?php
public function validate_shipping_address( $request ) {
	$valid_countries = wc()->countries->get_shipping_countries();

	if ( empty( $request['country'] ) ) {
		throw new RouteException(
			'woocommerce_rest_cart_shipping_rates_missing_country',
			sprintf(
				/* translators: 1: valid country codes */
				__( 'No destination country code was given. Please provide one of the following: %s', 'woocommerce' ),
				implode( ', ', array_keys( $valid_countries ) )
			),
			400
		);
	}

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

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

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

	if ( ! empty( $request['state'] ) ) {
		$valid_states = wc()->countries->get_states( $request['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 ) ) );
			$request['state']   = wc_strtoupper( $request['state'] );

			if ( isset( $valid_state_values[ $request['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.
				$request['state'] = $valid_state_values[ $request['state'] ];
			}

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

	return $request;
}