[Experimental] Update args for `woocommerce_blocks_validate_additional_field_{key}` filter (#44012)
This commit is contained in:
parent
1ea439fb61
commit
0ecb53f61c
|
@ -0,0 +1,5 @@
|
|||
Significance: patch
|
||||
Type: update
|
||||
Comment: This is behind a feature flag for now.
|
||||
|
||||
|
|
@ -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 ) {
|
||||
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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() ) {
|
||||
|
|
Loading…
Reference in New Issue