Automattic\WooCommerce\Blocks\Domain\Services

CheckoutFields::process_checkbox_field()privateWC 1.0

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

Method of the class: CheckoutFields{}

No Hooks.

Return

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

Usage

// private - for code of main (parent) class only
$result = $this->process_checkbox_field( $field_data, $options );
$field_data(array) (required)
The field data array to be updated.
$options(array) (required)
The options supplied during field registration.

CheckoutFields::process_checkbox_field() code WC 9.7.1

private function process_checkbox_field( $field_data, $options ) {
	$id = $options['id'];

	// Checkbox fields are always optional. Log a warning if it's set explicitly as true.
	$field_data['required'] = false;

	if ( isset( $options['required'] ) && true === $options['required'] ) {
		$message = sprintf( 'Registering checkbox fields as required is not supported. "%s" will be registered as optional.', $id );
		_doing_it_wrong( 'woocommerce_register_additional_checkout_field', esc_html( $message ), '8.6.0' );
	}

	return $field_data;
}