I am using the plugin WooCommerce Variation Swatches and Photos which lets me add a thumbnail to my product's attributes.
I need to list all the attributes on a template and I would like to also get and show the thumbnail.
$terms = get_terms( array(
'taxonomy' => 'pa_texture',
'hide_empty' => false,
) );
foreach ( $terms as $term ) {
print_r($term);
}
The thumbnail feature is not default in WooCommerce so when I print_r $term there is no thumbnail URL:
WP_Term Object
(
[term_id] => 54
[name] => Guilin
[slug] => guilin
[term_group] => 0
[term_taxonomy_id] => 54
[taxonomy] => pa_texture
[description] => Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla imperdiet facilisis convallis.
[parent] => 0
[count] => 2
[filter] => raw
[meta_value] => 0
)
How can I get the attribute's thumbnail image?
The classic way for product categories terms
'product_cat'
taxonomy is:Found the solution thanks to @Und3rTow's input.
The correct parameter in get_woocommerce_term_meta is
pa_texture_swatches_id_photo
.Here is the final code:
I had a similar problem when displaying images in upsells products. There is a mess, but:
See this code:
This is untested, however some variation of the following should work:
If you look at the relevant plugin file, you can see how the author get the images. The code above is based loosely from that.