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.

Method of the class: AbstractFieldType{}

No Hooks.

Returns

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

Usage

$AbstractFieldType = new AbstractFieldType();
$AbstractFieldType->default_validate( $value, $field );
$value(mixed) (required)
The submitted value.
$field(array) (required)
The field.

AbstractFieldType::default_validate() code WC 11.2.1

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']
			)
		);
	}
}