Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #182523

    Hello,
    I need some help with woocommerce. On my shop page (not single product page) I want to display the product category right between the product title and the product price. Is there an easy way without having to modify theme files (my site runs with an enfold child theme)? Any help would be greatly appreciated.
    Thanks.

    #182857

    Hi StuWeTueHo!

    You can use following code

    
    add_action( 'woocommerce_after_shop_loop_item_title', 'avia_add_product_cat', 1);
    function avia_add_product_cat()
    {
        global $product;
        $product_cats = wp_get_post_terms($product->id, 'product_cat');
        $count = count($product_cats);
        foreach($product_cats as $key => $cat)
        {
            echo $cat->name;
            if($key < ($count-1))
            {
                echo ', ';
            }
            else
            {
                echo '<br/>';
            }
        }
    }
    

    Insert it at the bottom of functions.php.

    Cheers!
    Peter

    #182871

    Works perfectly. Thanks Peter!
    Your support earns more than 5 stars.

    #182875

    Hi!

    Great, glad I could help you :)

    Best regards,
    Peter

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Display product category under title’ is closed to new replies.