• Resolved marktea1

    (@marktea1)


    I’m trying to display images attached to custom taxonomies on the individual product pages. I’ve used the Custom Taxonomy plugin and added the images using Advanced Custom Fields. I have 2 custom taxonomies called ‘range_logo’ and ‘features’, each with images assigned to them. I need to output the images to the single product page using the hook ‘woocommerce_before_add_to_cart_form’.

    As you can see below I have tried outputting a line of text to test if the hook is working correctly, and it is, but the taxonomy image isn’t shown when I add the code which is supplied with the plugin.

    add_action(
    “woocommerce_before_add_to_cart_form”,”product_taxonomy_image”);
    function product_taxonomy_image () {
    echo ‘Taxonomy image here’;
    print apply_filters( ‘taxonomy-images-queried-term-image’, ” );
    }

    Expected results are that the appropriate taxonomy image for the product would be displayed. Instead I got this error:

    Notice: term_taxonomy_id is not a property of the current queried object. This usually happens when the taxonomy-images-queried-term-image-id filter is used in an unsupported template file. This filter has been designed to work in taxonomy archives which are traditionally served by one of the following template files: category.php, tag.php or taxonomy.php. Learn more about template hierarchy. in /var/sites/a/mysite.com/public_html/wpnew/wp-content/plugins/taxonomy-images/legacy/includes/public-filters.php on line 398

    If it helps I’m using the Avada theme – maybe the layout of the theme’s template files could be the reason for the error? I think I may need to use archive.php instead, but unfortunately I don’t have much experience with PHP and I’ve hit a wall with getting this to work. Not sure what I should be trying next.

    Thanks for any help.

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Thread Starter marktea1

    (@marktea1)

    Problem solved!

    In case anyone else needs to know, this is the code to add to functions.php:

    add_action(“woocommerce_before_add_to_cart_form”,”product_taxonomy_image”);
    function product_taxonomy_image () {
    print apply_filters( ‘taxonomy-images-list-the-terms’, ”, array(
    ‘before’ => ‘<div class=”my-custom-class-name”>’,
    ‘after’ => ‘</div>’,
    ‘before_image’ => ‘<span>’,
    ‘after_image’ => ‘</span>’,
    ‘image_size’ => ‘detail’,
    ‘taxonomy’ => ‘product_cat’,
    ) );
    }

    Replace ‘product-cat’ with the taxonomy name. Add your own div name to div class then style accordingly in the custom CSS of your theme. You can also change the Woocommerce hook to display the image where you need it to be.

Viewing 1 replies (of 1 total)
  • The topic ‘Display taxonomy images in front end in Avada theme’ is closed to new replies.