[ 'type' => 'toggle', 'title' => __('Default State', 'wp-ultimo'), 'desc' => __('Use the toggle to the set the default state of the checkbox.', 'wp-ultimo'), 'value' => 0, 'order' => 12, ], ]; } /** * Returns the field/element actual field array to be used on the checkout form. * * @since 2.0.0 * * @param array $attributes Attributes saved on the editor form. * @return array An array of fields, not the field itself. */ public function to_fields_array($attributes) { $checkout_fields = []; $checkout_fields[ $attributes['id'] ] = [ 'type' => 'checkbox', 'id' => $attributes['id'], 'name' => $attributes['name'], 'tooltip' => $attributes['tooltip'], 'required' => $attributes['required'], 'wrapper_classes' => $attributes['element_classes'], ]; if ($attributes['default_state']) { $checkout_fields[ $attributes['id'] ]['html_attr']['checked'] = 'checked'; } $value = $this->get_value(); if ('' !== $value && (bool) $value === true) { $checkout_fields[ $attributes['id'] ]['html_attr']['checked'] = 'checked'; } return $checkout_fields; } }