[Support request] Display Product Category image on top of product name on single product page

Home Forums Support Display Product Category image on top of product name on single product page

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

    Hello, Id like to be able to display the Category image from Product categories above the single-product page Title?

    #1419273
    David
    Staff
    Customer Support

    Hi there,

    you can use a Hook Element:

    https://docs.generatepress.com/article/hooks-element-overview/

    Add this code:

    <?php
    global $wp_query;
        $terms_post = get_the_terms( $post->cat_ID , 'product_cat' );
        foreach ($terms_post as $term_cat) { 
        $thumbnail_id = $term_cat->term_id; 
        $image = wp_get_attachment_image_src( $thumbnail_id, 'thumbnail' );
        echo '<img class="woo-single-category-image" src="'.$image[0].'" />';
    }
    ?>

    Select the woocommerce_before_single_product_summary hook.
    Check execute PHP
    And set the Display Rules to Product > All Products

    #1420915
    HJ

    Thanks, updated with code
    But im not seeing anything..

    #1421804
    David
    Staff
    Customer Support

    I tested that code on a default woo install it works correctly.
    On your site i am seeing it has output img tags but with no src which i can only assume is some other code is at play, maybe another plugin or custom template.

    Might be worth asking on Woo support to see if they have a solution

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.