diff --git a/plugins/woocommerce/changelog/remove-schema-from-additional-fields-filter b/plugins/woocommerce/changelog/remove-schema-from-additional-fields-filter new file mode 100644 index 00000000000..a29db88b7c5 --- /dev/null +++ b/plugins/woocommerce/changelog/remove-schema-from-additional-fields-filter @@ -0,0 +1,5 @@ +Significance: patch +Type: update +Comment: This is behind a feature flag for now. + + diff --git a/plugins/woocommerce/src/Blocks/Domain/Services/CheckoutFields.php b/plugins/woocommerce/src/Blocks/Domain/Services/CheckoutFields.php index 3b9e92e4a16..0080be51288 100644 --- a/plugins/woocommerce/src/Blocks/Domain/Services/CheckoutFields.php +++ b/plugins/woocommerce/src/Blocks/Domain/Services/CheckoutFields.php @@ -538,12 +538,12 @@ class CheckoutFields { * * @param string $key The key of the field. * @param mixed $field_value The value of the field. - * @param array $field_schema The schema of the field. * @param \WP_REST_Request $request The current API Request. + * @param string|null $address_type The type of address (billing, shipping, or null if the field is a contact/additional field). * * @since 8.6.0 */ - public function validate_field( $key, $field_value, $field_schema, $request ) { + public function validate_field( $key, $field_value, $request, $address_type = null ) { $error = new \WP_Error(); try { @@ -552,12 +552,12 @@ class CheckoutFields { * * @param \WP_Error $error A WP_Error that extensions may add errors to. * @param mixed $field_value The value of the field. - * @param array $field_schema The schema of the field. * @param \WP_REST_Request $request The current API Request. + * @param string|null $address_type The type of address (billing, shipping, or null if the field is a contact/additional field). * * @since 8.6.0 */ - $filtered_result = apply_filters( 'woocommerce_blocks_validate_additional_field_' . $key, $error, $field_value, $field_schema, $request ); + $filtered_result = apply_filters( 'woocommerce_blocks_validate_additional_field_' . $key, $error, $field_value, $request, $address_type ); if ( $error !== $filtered_result ) { diff --git a/plugins/woocommerce/src/StoreApi/Schemas/V1/AbstractAddressSchema.php b/plugins/woocommerce/src/StoreApi/Schemas/V1/AbstractAddressSchema.php index 3d38d4a1e09..3c541c1cebf 100644 --- a/plugins/woocommerce/src/StoreApi/Schemas/V1/AbstractAddressSchema.php +++ b/plugins/woocommerce/src/StoreApi/Schemas/V1/AbstractAddressSchema.php @@ -217,11 +217,12 @@ abstract class AbstractAddressSchema extends AbstractSchema { // Check if a field is in the list of additional fields then validate the value against the custom validation rules defined for it. // Skip additional validation if the schema validation failed. if ( true === $result && in_array( $key, $additional_keys, true ) ) { - $result = $this->additional_fields_controller->validate_field( $key, $address[ $key ], $properties[ $key ], $request ); + $address_type = 'shipping_address' === $this->title ? 'shipping' : 'billing'; + $result = $this->additional_fields_controller->validate_field( $key, $address[ $key ], $request, $address_type ); } if ( is_wp_error( $result ) && $result->has_errors() ) { - $errors->add( $result->get_error_code(), $result->get_error_message() ); + $errors->merge_from( $result ); } } diff --git a/plugins/woocommerce/src/StoreApi/Schemas/V1/CheckoutSchema.php b/plugins/woocommerce/src/StoreApi/Schemas/V1/CheckoutSchema.php index 178e6b80321..41ea38bfcc6 100644 --- a/plugins/woocommerce/src/StoreApi/Schemas/V1/CheckoutSchema.php +++ b/plugins/woocommerce/src/StoreApi/Schemas/V1/CheckoutSchema.php @@ -373,7 +373,7 @@ class CheckoutSchema extends AbstractSchema { // Only allow custom validation on fields that pass the schema validation. if ( true === $result ) { - $result = $this->additional_fields_controller->validate_field( $key, $field_value, $properties[ $key ], $request ); + $result = $this->additional_fields_controller->validate_field( $key, $field_value, $request ); } if ( is_wp_error( $result ) && $result->has_errors() ) {