• Resolved marcoatmac

    (@marcoatmac)


    Hi, I have more products without images and I would like to substitute with is category’s image.

    I find this function but the problem is that the add the image category on the shop page doesn’t substitute the featured image, somebody can help me to fix it, please?

    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' );
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Image product from his category’ is closed to new replies.