Prevent error on Cart Shipping Calculator when using Additional Checkout Fields API (#49685)

This commit is contained in:
Thomas Roberts 2024-07-23 16:38:54 +01:00 committed by GitHub
parent e8d899b6f3
commit ad7a49df4c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 1 deletions

View File

@ -73,7 +73,13 @@ const ShippingCalculatorAddress = ( {
const isAddressValid = validateSubmit();
if ( isAddressValid ) {
return onUpdate( address );
const addressToSubmit = {};
addressFields.forEach( ( key ) => {
if ( typeof address[ key ] !== 'undefined' ) {
addressToSubmit[ key ] = address[ key ];
}
} );
return onUpdate( addressToSubmit );
}
} }
type="submit"

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Prevent a warning showing when using the Shipping Address Calculator in combination with the additional checkout fields API

View File

@ -172,6 +172,13 @@ abstract class AbstractAddressSchema extends AbstractSchema {
// correct format, and finally the second validation step is to ensure the correctly-formatted values
// match what we expect (postcode etc.).
foreach ( $address as $key => $value ) {
// Only run specific validation on properties that are defined in the schema and present in the address.
// This is for partial address pushes when only part of a customer address is sent.
// Full schema address validation still happens later, so empty, required values are disallowed.
if ( empty( $schema[ $key ] ) || empty( $address[ $key ] ) ) {
continue;
}
if ( is_wp_error( rest_validate_value_from_schema( $value, $schema[ $key ], $key ) ) ) {
$errors->add(
'invalid_' . $key,