Automattic\WooCommerce\Blocks\Domain\Services

CheckoutFieldsFrontend::get_posted_additional_field_valuesprotectedWC 1.0

Get posted additional field values.

Method of the class: CheckoutFieldsFrontend{}

No Hooks.

Returns

Array. The posted field values and sanitized field values.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_posted_additional_field_values( $location, $group, $sanitize );
$location(string) (required)
The location to get fields for.
$group(string) (required)
The group to get fields for.
$sanitize(true|false)
Whether to sanitize the field values.
Default: true

CheckoutFieldsFrontend::get_posted_additional_field_values() code WC 9.8.5

protected function get_posted_additional_field_values( $location, $group, $sanitize = true ) {
	$additional_fields = $this->checkout_fields_controller->get_fields_for_location( $location );
	$field_values      = [];

	// phpcs:disable WordPress.Security.NonceVerification.Missing
	foreach ( $additional_fields as $field_key => $field_data ) {
		$post_key                   = CheckoutFields::get_group_key( $group ) . $field_key;
		$field_values[ $field_key ] = wc_clean( wp_unslash( $_POST[ $post_key ] ?? '' ) );

		if ( $sanitize ) {
			$field_values[ $field_key ] = $this->checkout_fields_controller->sanitize_field( $field_key, $field_values[ $field_key ] );
		}
	}
	// phpcs:enable WordPress.Security.NonceVerification.Missing
	return $field_values;
}