PHP Warning: Undefined variable $field_values in CheckoutFieldsFrontend.php
-
Thank you for WooCommerce 9.8.1 release.
After changing the password on the My Account screen (/my-account/edit-account/), warning was logged in debug.log below (WooCommerce9.8.1+PHP8.3.10).
[10-Apr-2025 08:55:37 UTC] PHP Warning: Undefined variable $field_values in /***/wp-content/plugins/woocommerce/src/Blocks/Domain/Services/CheckoutFieldsFrontend.php on line 312
protected function get_posted_additional_field_values( $location, $group, $sanitize = true ) { $additional_fields = $this->checkout_fields_controller->get_fields_for_location( $location ); // phpcs:disable WordPress.Security.NonceVerification.Missing foreach ( $additional_fields as $field_key => $field_data ) { $post_key = CheckoutFields::get_group_key( $group ) . $field_key; $field_values[ $field_key ] = wc_clean( wp_unslash( $_POST[ $post_key ] ?? '' ) ); if ( $sanitize ) { $field_values[ $field_key ] = $this->checkout_fields_controller->sanitize_field( $field_key, $field_values[ $field_key ] ); } } // phpcs:enable WordPress.Security.NonceVerification.Missing return $field_values; }When the foreach loop does not execute, the $field_values variable remains undefined, which results in a warning being logged.
Thank you for your time and support.
The topic ‘PHP Warning: Undefined variable $field_values in CheckoutFieldsFrontend.php’ is closed to new replies.