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

Automattic\WooCommerce\Blocks\StoreApi\Utilities

OrderController::validate_address_fields() protected WC 1.0

Check all required address fields are set and return errors if not.

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

Хуков нет.

Возвращает

null. Ничего.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->validate_address_fields( $address, $address_type, \WP_Error $errors );
$address(массив) (обязательный)
Address array.
$address_type(строка) (обязательный)
billing or shipping address, used in error messages.
\WP_Error $errors (обязательный)
-

Код OrderController::validate_address_fields() WC 5.2.2

<?php
protected function validate_address_fields( $address, $address_type, \WP_Error $errors ) {
	$all_locales    = wc()->countries->get_country_locale();
	$current_locale = isset( $all_locales[ $address['country'] ] ) ? $all_locales[ $address['country'] ] : [];

	/**
	 * We are not using wc()->counties->get_default_address_fields() here because that is filtered. Instead, this array
	 * is based on assets/js/base/components/cart-checkout/address-form/default-address-fields.js
	 */
	$address_fields = [
		'first_name' => [
			'label'    => __( 'First name', 'woocommerce' ),
			'required' => true,
		],
		'last_name'  => [
			'label'    => __( 'Last name', 'woocommerce' ),
			'required' => true,
		],
		'company'    => [
			'label'    => __( 'Company', 'woocommerce' ),
			'required' => false,
		],
		'address_1'  => [
			'label'    => __( 'Address', 'woocommerce' ),
			'required' => true,
		],
		'address_2'  => [
			'label'    => __( 'Apartment, suite, etc.', 'woocommerce' ),
			'required' => false,
		],
		'country'    => [
			'label'    => __( 'Country/Region', 'woocommerce' ),
			'required' => true,
		],
		'city'       => [
			'label'    => __( 'City', 'woocommerce' ),
			'required' => true,
		],
		'state'      => [
			'label'    => __( 'State/County', 'woocommerce' ),
			'required' => true,
		],
		'postcode'   => [
			'label'    => __( 'Postal code', 'woocommerce' ),
			'required' => true,
		],
	];

	if ( $current_locale ) {
		foreach ( $current_locale as $key => $field ) {
			if ( isset( $address_fields[ $key ] ) ) {
				$address_fields[ $key ]['label']    = isset( $field['label'] ) ? $field['label'] : $address_fields[ $key ]['label'];
				$address_fields[ $key ]['required'] = isset( $field['required'] ) ? $field['required'] : $address_fields[ $key ]['required'];
			}
		}
	}

	foreach ( $address_fields as $address_field_key => $address_field ) {
		if ( empty( $address[ $address_field_key ] ) && $address_field['required'] ) {
			/* translators: %s Field label. */
			$errors->add( $address_type, sprintf( __( '%s is required', 'woocommerce' ), $address_field['label'] ), $address_field_key );
		}
	}
}