Automattic\WooCommerce\Blocks\Domain\Services
CheckoutFields::validate_field_for_location
Validates a field to check it belongs to the given location and is valid according to its registration.
This does not apply any custom validation rules on the value.
Метод класса: CheckoutFields{}
Хуков нет.
Возвращает
true|WP_Error. True if the field is valid, a WP_Error otherwise.
Использование
$CheckoutFields = new CheckoutFields(); $CheckoutFields->validate_field_for_location( $key, $value, $location );
- $key(строка) (обязательный)
- The field key.
- $value(разное) (обязательный)
- The field value.
- $location(строка) (обязательный)
- The location to validate the field for (address|contact|order).
Код CheckoutFields::validate_field_for_location() CheckoutFields::validate field for location WC 10.6.2
public function validate_field_for_location( $key, $value, $location ) {
$location = $this->prepare_location_name( $location );
if ( ! $this->is_field( $key ) ) {
return new WP_Error(
'woocommerce_invalid_checkout_field',
\sprintf(
// translators: % is field key.
__( 'The field %s is invalid.', 'woocommerce' ),
$key
)
);
}
if ( ! in_array( $key, $this->fields_locations[ $location ], true ) ) {
return new WP_Error(
'woocommerce_invalid_checkout_field_location',
\sprintf(
// translators: %1$s is field key, %2$s location.
__( 'The field %1$s is invalid for the location %2$s.', 'woocommerce' ),
$key,
$location
)
);
}
return true;
}