wc_format_list_of_items()WC 1.0

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

Хуков нет.

Возвращает

Строку.

Использование

wc_format_list_of_items( $items );
$items(массив) (обязательный)
Cart items.

Код wc_format_list_of_items() 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;
}