Prevent error on Cart Shipping Calculator when using Additional Checkout Fields API (#49685)
This commit is contained in:
parent
e8d899b6f3
commit
ad7a49df4c
|
@ -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"
|
||||
|
|
|
@ -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
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue