wc_format_list_of_items

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

Description

(string) wc_format_list_of_items( (array) $items ); 

Returns (string)

Parameters (1)

0. $items (array)
The items.

Usage

  1. if ( !function_exists( 'wc_format_list_of_items' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-cart-functions.php'; 
  3.  
  4. // The items. 
  5. $items = array(); 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wc_format_list_of_items($items); 
  9.  

Defined (1)

The function is defined in the following location(s).

/includes/wc-cart-functions.php  
  1. function wc_format_list_of_items( $items ) { 
  2. $item_string = ''; 
  3.  
  4. foreach ( $items as $key => $item ) { 
  5. $item_string .= $item; 
  6.  
  7. if ( sizeof( $items ) === $key + 2 ) { 
  8. $item_string .= ' ' . __( 'and', woocommerce ) . ' '; 
  9. } elseif ( sizeof( $items ) !== $key + 1 ) { 
  10. $item_string .= ', '; 
  11.  
  12. return $item_string;