Site logo

[Resolved] Dynamic image block

Home Forums Support [Resolved] Dynamic image block

Home Forums Support Dynamic image block

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #2461552
    Søren

    I’m trying to use the product category thumbnail_id image as META FIELD NAME value when setting type = post meta, but it doesn’t output anything.

    When setting the type = Featured image it just shows the first product and I would like to use the product category image.

    Are there any other way of dynamic outputting a/the category image somehow?

    #2461589
    David
    Staff
    Customer Support

    Hi there,

    they store it in the term meta, so for now you would need to create a shortcode for that. Try this snippet:

    
    function show_woo_cat_image($html) {
        if ( is_product_category() ){
            global $wp_query;
            $cat = $wp_query->get_queried_object();
            $thumbnail_id = get_term_meta( $cat->term_id, 'thumbnail_id', true );
            $image = wp_get_attachment_url( $thumbnail_id );
            if ( $image ) {
                $html =  '<img src="' . $image . '" alt="' . $cat->name . '" />';
                return $html;
            }
        }
    }
    add_shortcode('show_cat_image', 'show_woo_cat_image' );

    Then add [show_cat_image] shortcode where you want it displayed.

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