0

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?

  • did you ever figure it out? – Zach Smith Mar 26 '18 at 10:44
  • Yes, I used get_woocommerce_term_meta. I will answer the question with the solution – Jeff Mar 27 '18 at 10:48
0

I resolved it by using get_woocommerce_term_meta

$terms = get_terms( array(
    'taxonomy' => 'pa_texture',
    'hide_empty' => false,
));
foreach ( $terms as $term ) :
    $thumbnail_id = get_woocommerce_term_meta( $term->term_id, 'pa_texture_swatches_id_photo', true );
    $textureImg = wp_get_attachment_image_src( $thumbnail_id, 'full' ); ?>
    <img src="<?php echo $textureImg[0]; ?>">
endforeach;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.