Automattic\WooCommerce\Blocks\Domain\Services
CheckoutFields::validate_fields_for_location()
Validates a set of fields for a given location against custom validation rules.
Метод класса: CheckoutFields{}
Хуки из метода
Возвращает
WP_Error
.
Использование
$CheckoutFields = new CheckoutFields(); $CheckoutFields->validate_fields_for_location( $fields, $location, $group );
- $fields(массив) (обязательный)
- Array of key value pairs of field values to validate.
- $location(строка) (обязательный)
- The location being validated (address|contact|order).
- $group(строка)
- The group to get the field value for (shipping|billing|other).
По умолчанию: 'other'
Код CheckoutFields::validate_fields_for_location() CheckoutFields::validate fields for location WC 9.6.0
public function validate_fields_for_location( $fields, $location, $group = 'other' ) { $errors = new WP_Error(); if ( 'additional' === $location ) { wc_deprecated_argument( 'location', '8.9.0', 'The "additional" location is deprecated. Use "order" instead.' ); $location = 'order'; } if ( 'additional' === $group ) { wc_deprecated_argument( 'group', '8.9.0', 'The "additional" group is deprecated. Use "other" instead.' ); $group = 'other'; } try { /** * 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.6.0 * @deprecated 8.9.0 Use woocommerce_blocks_validate_location_order_fields instead. */ wc_do_deprecated_action( 'woocommerce_blocks_validate_location_additional_fields', array( $errors, $fields, $group ), '8.9.0', 'woocommerce_blocks_validate_location_additional_fields', 'This action has been graduated, use woocommerce_blocks_validate_location_additional_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.6.0 * @deprecated 8.9.0 Use woocommerce_blocks_validate_location_{location}_fields instead. */ 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; }