wc_format_dimensions()WC 3.0.0

Format dimensions for display.

Hooks from the function

Return

String.

Usage

wc_format_dimensions( $dimensions );
$dimensions(array) (required)
Array of dimensions.

Changelog

Since 3.0.0 Introduced.

wc_format_dimensions() code WC 8.9.0

function wc_format_dimensions( $dimensions ) {
	$dimension_string = implode( ' × ', array_filter( array_map( 'wc_format_localized_decimal', $dimensions ) ) );

	if ( ! empty( $dimension_string ) ) {
		$dimension_label = I18nUtil::get_dimensions_unit_label( get_option( 'woocommerce_dimension_unit' ) );

		$dimension_string = sprintf(
			// translators: 1. A formatted number; 2. A label for a dimensions unit of measure. E.g. 3.14 cm.
			_x( '%1$s %2$s', 'formatted dimensions', 'woocommerce' ),
			$dimension_string,
			$dimension_label
		);
	} else {
		$dimension_string = __( 'N/A', 'woocommerce' );
	}

	return apply_filters( 'woocommerce_format_dimensions', $dimension_string, $dimensions );
}