Automattic\WooCommerce\Blocks\Domain\Services

CheckoutFields::is_valid_fieldpublicWC 1.0

Validates a field against the given document object and context.

Method of the class: CheckoutFields{}

No Hooks.

Returns

true|false|\WP_Error. True if the field is valid, a WP_Error otherwise.

Usage

$CheckoutFields = new CheckoutFields();
$CheckoutFields->is_valid_field( $field, $document_object );
$field(array) (required)
The field.
$document_object(DocumentObject|null)
The document object.
Default: null

CheckoutFields::is_valid_field() code WC 9.9.3

public function is_valid_field( $field, $document_object = null ) {
	if ( $document_object && $this->contains_valid_rules( $field['validation'] ) ) {
		$field_schema = Validation::get_field_schema_with_context( $field['id'], $field['validation'], $document_object->get_context() );
		return Validation::validate_document_object( $document_object, $field_schema );
	}
	return true;
}