| @@ -239,9 +239,17 @@ | ||
| 239 | 239 | $name = $field['name'] ?? ''; |
| 240 | 240 | $label = $field['label'] ?? ''; |
| 241 | 241 | $required = $field['required'] ?? false; |
| 242 | 242 | $container_class = $field['container_class'] ?? 'sm:col-span-6'; |
| 243 | - $value = (boolean)$item_value ; | |
| 243 | + // A new row (the template, index -1, or no stored value at all) takes | |
| 244 | + // the field's default; "Taxable" defaults to on, so a line added | |
| 245 | + // with tax enabled is taxed unless the merchant unticks it. A stored | |
| 246 | + // '0' stays off. | |
| 247 | + if (null === $item_value || '' === $item_value) { | |
| 248 | + $default = $field['default_value'] ?? ''; | |
| 249 | + $item_value = is_callable($default) ? (string) $default() : (string) $default; | |
| 250 | + } | |
| 251 | + $value = ('1' === (string) $item_value || 'true' === (string) $item_value || 'yes' === (string) $item_value || 'on' === (string) $item_value); | |
| 244 | 252 | $description = $field['description'] ?? ''; |
| 245 | 253 | $required_attr = $required ? 'required' : ''; |
| 246 | 254 | $required_class = $required ? 'required' : ''; |
| 247 | 255 | $checked = ($value == '1' || $value === true) ? 'checked' : ''; |