Skip to content

Commit daf00c3

Browse files
annemirasoldaledupreez
authored andcommitted
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]> Cherry-picked from ea2a035
1 parent f95defe commit daf00c3

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
@@ -3,6 +3,7 @@
33
= 9.7.1 - xxxx-xx-xx =
44
* Add - Add state mapping for Lithuania in express checkout
55
* Tweak - Check for checkout validation error before creating a payment method in Stripe
6+
* Fix - Fix required field error message and PHP warning for custom checkout fields that don't have a label
67

78
= 9.7.0 - 2025-07-21 =
89
* 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
@@ -113,6 +113,7 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
113113
= 9.7.1 - xxxx-xx-xx
114114
* Add - Add state mapping for Lithuania in express checkout
115115
* Tweak - Check for checkout validation error before creating a payment method in Stripe
116+
* Fix - Fix required field error message and PHP warning for custom checkout fields that don't have a label
116117

117118
= 9.7.0 - 2025-07-21 =
118119

0 commit comments

Comments
 (0)