wc_format_list_of_items()
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() wc format list of items code WC 9.3.1
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; }