-2

Could you help me a little? I used this snippet, is working well.

add_action( 'woocommerce_single_product_summary', 'product_attribute_dimensions', 45 );
function product_attribute_dimensions(){
    global $product;

    $taxonomy = 'pa_dimensions';
    $value = $product->get_attribute( $taxonomy );

    if ( $value ) {
        $label = get_taxonomy( $taxonomy )->labels->singular_name;

        echo '<p>' . $label . ': ' . $value . '</p>';
    }
}

https://stackoverflow.com/a/49602770/17244939

But I can't figure, how I can display the attribute attached image and not the text. Could you help me?

Mainul Hasan
  • 691
  • 3
  • 12
  • You can check this answer https://stackoverflow.com/questions/55801999/display-custom-taxonomy-term-images-for-woocommerce-product-attributes – Mainul Hasan Oct 26 '21 at 03:23
  • 1
    By default attributes dont have image so if you use a plugin or another piece of code for that you need to debug your term to find what data holds and then grab it. – Snuffy Oct 26 '21 at 06:20

1 Answers1

0
global $product;

$ingredients = $product->get_attributes( 'color' );

foreach( $ingredients as $attr_name => $attr ){
    foreach( $attr->get_terms() as $term ){
        if ( wc_attribute_label( $attr_name ) == "Color" ) {
            echo $term->name ;
            $meta_image = get_wp_term_image($term->term_id);
            echo '<img src="'.$meta_image.'"/>';
        } 
        else echo '';
    }
}

Can you try with above Code and color replace with your attribute