Automattic\WooCommerce\Blocks\Domain\Services
CheckoutFields::validate_fields_for_location()
Validates a set of fields for a given location against custom validation rules.
Method of the class: CheckoutFields{}
Hooks from the method
Returns
WP_Error
.
Usage
$CheckoutFields = new CheckoutFields(); $CheckoutFields->validate_fields_for_location( $fields, $location, $group );
- $fields(array) (required)
- Array of key value pairs of field values to validate.
- $location(string) (required)
- The location being validated (address|contact|order).
- $group(string)
- The group to get the field value for (shipping|billing|other).
Default: 'other'
CheckoutFields::validate_fields_for_location() CheckoutFields::validate fields for location code WC 9.8.5
public function validate_fields_for_location( $fields, $location, $group = 'other' ) { $errors = new WP_Error(); $location = $this->prepare_location_name( $location ); $group = $this->prepare_group_name( $group ); try { wc_do_deprecated_action( '__experimental_woocommerce_blocks_validate_location_' . $location . '_fields', array( $errors, $fields, $group ), '8.9.0', 'woocommerce_blocks_validate_location_' . $location . '_fields', 'This action has been graduated, use woocommerce_blocks_validate_location_' . $location . '_fields instead.' ); /** * Pass an error object to allow validation of an additional field. * * @param WP_Error $errors A WP_Error object that extensions may add errors to. * @param mixed $fields List of fields (key value pairs) in this location. * @param string $group The group of this location (shipping|billing|other). * * @since 8.7.0 */ do_action( 'woocommerce_blocks_validate_location_' . $location . '_fields', $errors, $fields, $group ); } catch ( \Throwable $e ) { // One of the filters errored so skip them. This allows the checkout process to continue. // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error trigger_error( sprintf( 'The action %s encountered an error. The field location %s may not have any custom validation applied to it. %s', esc_html( 'woocommerce_blocks_validate_' . $location . '_fields' ), esc_html( $location ), esc_html( $e->getMessage() ) ), E_USER_WARNING ); } return $errors; }