Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi @reichlich,

    The snippet that’s mentioned in that post is for adding the category image to a category archive. It has a “check” in it to make sure the page displayed is a category archive.

    
    if ( is_product_category() ){
    

    This will return false on a single product page which will keep the code inside it from running. Does that make sense?

    See if something like this will work instead:

    
    function ijab_category_image_single_product() {
        $terms = get_the_terms( $post->ID, 'product_cat' );
        foreach ( $terms as $term ){
            $category_name = $term->name;
            $category_thumbnail = get_woocommerce_term_meta($term->term_id, 'thumbnail_id', true);
            $image = wp_get_attachment_url($category_thumbnail);
            echo '<img src="'.$image.'" alt="'.$category_name.'">';
        }
    }
    add_action( 'woocommerce_after_add_to_cart_form', 'ijab_category_image_single_product' );
    

    On my test site, it did add the category image to the single product page.

    single product category image

    Thread Starter Reichlich

    (@reichlich)

    Hello @3sonsdevelopment

    Working 500% perfekt

    thanks for your help

    Danke

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to show Category image in product page’ is closed to new replies.