wc_format_list_of_items()WC 1.0

Comma separate a list of item names, and replace final comma with 'and'.

No Hooks.

Return

String.

Usage

wc_format_list_of_items( $items );
$items(array) (required)
Cart items.

wc_format_list_of_items() code WC 8.7.0

function wc_format_list_of_items( $items ) {
	$item_string = '';

	foreach ( $items as $key => $item ) {
		$item_string .= $item;

		if ( count( $items ) === $key + 2 ) {
			$item_string .= ' ' . __( 'and', 'woocommerce' ) . ' ';
		} elseif ( count( $items ) !== $key + 1 ) {
			$item_string .= ', ';
		}
	}

	return $item_string;
}