wc_format_list_of_items( array $items )

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


Description Description


Parameters Parameters

$items

(Required) Cart items.


Top ↑

Return Return

(string)


Top ↑

Source Source

File: includes/wc-cart-functions.php

148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
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;
}


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.