Automattic\WooCommerce\Blocks\Domain\Services\CheckoutFieldTypes
CheckboxFieldType::process_type_options
Processes the options for a checkbox field and returns the new field_options array.
Method of the class: CheckboxFieldType{}
No Hooks.
Returns
array|false. The updated $field_data array, or false if an error was encountered.
Usage
// protected - for code of main (parent) or child class $result = $this->process_type_options( $field_data, $options );
- $field_data(array) (required)
- The field data array to be updated.
- $options(array) (required)
- The options supplied during field registration.
CheckboxFieldType::process_type_options() CheckboxFieldType::process type options code WC 11.2.1
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;
}