Automattic\WooCommerce\Blocks\Domain\Services

CheckoutFields::format_additional_field_value()publicWC 1.0

Formats a raw field value for display based on its type definition.

Method of the class: CheckoutFields{}

No Hooks.

Return

String.

Usage

$CheckoutFields = new CheckoutFields();
$CheckoutFields->format_additional_field_value( $value, $field );
$value(string) (required)
Value to format.
$field(array) (required)
Additional field definition.

CheckoutFields::format_additional_field_value() code WC 9.0.1

public function format_additional_field_value( $value, $field ) {
	if ( 'checkbox' === $field['type'] ) {
		$value = $value ? __( 'Yes', 'woocommerce' ) : __( 'No', 'woocommerce' );
	}

	if ( 'select' === $field['type'] ) {
		$options = array_column( $field['options'], 'label', 'value' );
		$value   = isset( $options[ $value ] ) ? $options[ $value ] : $value;
	}

	return $value;
}