Automattic\WooCommerce\Blocks\Domain\Services\CheckoutFieldTypes

AbstractFieldType::default_validate │ public │ WC 1.0

The validate_callback a field gets when it does not declare its own: rejects empty required fields.

Unlike validate(), a field's validate_callback can be replaced at registration, so nothing here is mandatory for the type.

Метод класса: AbstractFieldType{}

Хуков нет.

Возвращает

WP_Error|void. An error if the value is invalid.

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

$AbstractFieldType = new AbstractFieldType();
$AbstractFieldType->default_validate( $value, $field );
$value(разное) (обязательный)
The submitted value.
$field(массив) (обязательный)
The field.

Код AbstractFieldType::default_validate() WC 11.2.2

public function default_validate( $value, $field ) {
	if ( true === $field['required'] && empty( $value ) ) {
		return new WP_Error(
			'woocommerce_required_checkout_field',
			sprintf(
				// translators: %s is field key.
				__( 'The field %s is required.', 'woocommerce' ),
				$field['id']
			)
		);
	}
}