Automattic\WooCommerce\Blocks\Domain\Services\CheckoutFieldTypes

DateFieldType::get_constraints │ private │ WC 1.0

Returns the resolved min and max dates for a date field.

Method of the class: DateFieldType{}

No Hooks.

Returns

array. Array with "min" and "max" keys, each a YYYY-MM-DD date or null when unconstrained.

Usage

// private - for code of main (parent) class only
$result = $this->get_constraints( $field, $log_invalid_range ): array;
$field(array) (required)
The field.
$log_invalid_range(true|false)
Whether to log an invalid range during value validation.
Default: false

DateFieldType::get_constraints() code WC 11.3.0

private function get_constraints( array $field, bool $log_invalid_range = false ): array {
	$constraints = array(
		'min' => isset( $field['min'] ) ? $this->resolve_constraint( $field['min'] ) : null,
		'max' => isset( $field['max'] ) ? $this->resolve_constraint( $field['max'] ) : null,
	);

	if ( isset( $constraints['min'], $constraints['max'] ) && $constraints['min'] > $constraints['max'] ) {
		if ( $log_invalid_range ) {
			wc_get_logger()->warning(
				sprintf( 'Date limits for checkout field "%s" were ignored because min (%s) is after max (%s).', $field['id'], $constraints['min'], $constraints['max'] ),
				array( 'source' => 'checkout-fields' )
			);
		}

		return array(
			'min' => null,
			'max' => null,
		);
	}

	return $constraints;
}