Skip to content

Commit ea2a035

Browse files
Fix "undefined array key 'label' warning" (#4519)
* Guard against undefined custom field label * Add readme and changelog entries * Update changelog.txt Co-authored-by: daledupreez <[email protected]> * Update readme.txt --------- Co-authored-by: daledupreez <[email protected]>
1 parent dbd1931 commit ea2a035

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* Tweak - Use wp_ajax prefix for its built-in security for Add Payment Method action
1212
* Dev - Fix WooCommerce version fetching in GitHub workflows
1313
* Dev - Fix failing test cases associated with WooCommerce 10.0.x
14+
* Fix - Fix required field error message and PHP warning for custom checkout fields that don't have a label
1415

1516
= 9.7.0 - 2025-07-21 =
1617
* Update - Removes BNPL payment methods (Klarna and Affirm) when other official plugins are active

includes/payment-methods/class-wc-stripe-express-checkout-custom-fields.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function process_custom_checkout_data( $order, $request ) {
5959
$required_field_errors[] = sprintf(
6060
/* translators: %s: field name */
6161
__( '%s is a required field.', 'woocommerce-gateway-stripe' ),
62-
$field['label']
62+
empty( $field['label'] ) ? $key : $field['label']
6363
);
6464
}
6565
}
@@ -197,7 +197,7 @@ public function get_custom_checkout_fields( $context = '' ) {
197197
$additional_fields = $checkout_fields->get_additional_fields();
198198
foreach ( $additional_fields as $field_key => $field ) {
199199
$block_custom_checkout_fields[ $field_key ] = [
200-
'label' => $field['label'],
200+
'label' => $field['label'] ?? '',
201201
'type' => $field['type'] ?? 'text',
202202
'location' => $checkout_fields->get_field_location( $field_key ),
203203
'required' => $field['required'] ?? false,
@@ -222,7 +222,7 @@ public function get_custom_checkout_fields( $context = '' ) {
222222
}
223223

224224
$classic_custom_checkout_fields[ $field_key ] = [
225-
'label' => $field['label'],
225+
'label' => $field['label'] ?? '',
226226
'type' => $field['type'] ?? 'text',
227227
'location' => $fieldset,
228228
'required' => $field['required'] ?? false,

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,5 +121,6 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
121121
* Tweak - Use wp_ajax prefix for its built-in security for Add Payment Method action
122122
* Dev - Fix WooCommerce version fetching in GitHub workflows
123123
* Dev - Fix failing test cases associated with WooCommerce 10.0.x
124+
* Fix - Fix required field error message and PHP warning for custom checkout fields that don't have a label
124125

125126
[See changelog for full details across versions](https://raw.githubusercontent.com/woocommerce/woocommerce-gateway-stripe/trunk/changelog.txt).

0 commit comments

Comments
 (0)