Prikaz kategorije ispod naziva proizvoda u košarici

Ponekad je korisno prikazati naziv kategorije ispod naziva proizvoda, ovaj snipet upravo to i omogućuje.

add_filter( 'woocommerce_cart_item_name', 'add_category_to_cart_item_name', 10, 3 );
function add_category_to_cart_item_name( $name, $cart_item, $cart_item_key ) {
    $product = $cart_item['data'];
    $categories = get_the_terms( $product->get_id(), 'product_cat' );
    if ( ! empty( $categories ) ) {
        $category_names = wp_list_pluck( $categories, 'name' );
        $name .= '<br><span class="product-category">Kategorija: ' . implode( ', ', $category_names ) . '</span>';
    return $name;
Get full Code Editor experience inside WordPress with support to write PHP hooks and functions, JavaScript, CSS, and compile SCSS.
Scripts Organiser
Recoda Codesense is set of the custom CodeMirror integrations with Oxygen builder to have the best code writing experience inside Oxygen Builder.