Automattic\WooCommerce\Blocks\Domain\Services\CheckoutFieldTypes

CheckboxFieldType::process_type_options │ protected │ WC 1.0

Processes the options for a checkbox field and returns the new field_options array.

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

Хуков нет.

Возвращает

array|false. The updated $field_data array, or false if an error was encountered.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->process_type_options( $field_data, $options );
$field_data(массив) (обязательный)
The field data array to be updated.
$options(массив) (обязательный)
The options supplied during field registration.

Код CheckboxFieldType::process_type_options() WC 11.2.2

protected function process_type_options( array $field_data, array $options ) {
	$id                     = $options['id'];
	$field_data['required'] = $options['required'] ?? false;

	if ( false === $field_data['required'] && ! empty( $options['error_message'] ) ) {
		$this->doing_it_wrong( sprintf( 'Passing an error message to a non-required checkbox "%s" will have no effect. The error message has been removed from the field.', $id ), '9.8.0' );
		unset( $field_data['error_message'] );
	}

	if ( isset( $options['error_message'] ) && ! is_string( $options['error_message'] ) ) {
		$this->doing_it_wrong( sprintf( 'The error_message property for field with id: "%s" must be a string, you passed %s. A default message will be shown.', $id, gettype( $options['error_message'] ) ), '9.8.0' );
		unset( $field_data['error_message'] );
	}

	// The client expects the error message in camelCase.
	if ( isset( $field_data['error_message'] ) ) {
		$field_data['errorMessage'] = $field_data['error_message'];
		unset( $field_data['error_message'] );
	}

	return $field_data;
}