Technical Report: Apple Pay “Missing Field” Validation Error
Context:
- Issue: Apple Pay transactions fail during the validation phase with a
400 Bad Request from the WooCommerce Store API.
- Environment: WooCommerce + Stripe Gateway (Apple Pay enabled).
- Error Message:
woocommerce_rest_invalid_address — “billing: [ is required ]” or “First name is required”.
1. Initial Bug (State/Region Requirement)
The Stripe Gateway was incorrectly requiring the address->state field for countries like France, even when not required by the country locale or when Apple Pay’s sheet does not provide it.
Action taken:
Applied a filter to bypass Stripe’s internal customer field validation for the state.
PHP
add_filter( 'wc_stripe_create_customer_required_fields', function( $required_fields ) {
if ( isset( $required_fields['state'] ) ) {
unset( $required_fields['state'] );
}
return $required_fields;
});
2. Conflict with “Checkout Form Designer” Plugin
While investigating, we found that a third-party plugin (Checkout Form Designer) was hiding the “State” field but also stripping the label key from the field array.
- Impact: This caused the WooCommerce Store API to crash with an
Undefined array key "label" error in OrderController.php:500 while trying to generate the validation error message.
Action taken:
- The plugin was deactivated to restore standard WooCommerce field metadata.
3. Persistent “First Name” Validation Failure
After deactivating the designer plugin and fixing the “State” issue, the Store API continued to return a 400 error claiming “First Name is required”, even though the Apple Pay payload contained the user’s name.
Action taken (Temporary Workaround):
To bypass this block and allow orders to process, we had to force the First Name and Last Name fields to required => false at the root level.
PHP
add_filter( 'woocommerce_default_address_fields', 'force_unrequire_names_root', 99999 );
function force_unrequire_names_root( $fields ) {
if ( isset( $fields['first_name'] ) ) $fields['first_name']['required'] = false;
if ( isset( $fields['last_name'] ) ) $fields['last_name']['required'] = false;
return $fields;
}
Summary of Logs for Debugging
JSON
{
"code": "woocommerce_rest_invalid_address",
"message": "First name is required",
"last_error": {
"type": 2,
"message": "Undefined array key 'label'",
"file": ".../plugins/woocommerce/src/StoreApi/Utilities/OrderController.php",
"line": 500
}
}
Questions for the Developer:
- Why is the Store API failing to map the
billing_first_name from the Apple Pay payload to the order, triggering a “required” field error?
- Why does the WooCommerce
OrderController.php (line 500) not have a fallback when a field’s label is missing, causing a fatal-level error instead of a graceful validation?
- Is there a known conflict between the Stripe Gateway’s Apple Pay integration and the WooCommerce Store API regarding address validation for “state-less” countries?