Can’t say as I’ve gotten to figuring out which bit of code you need. I’ve spent the time I’ve had since finding your post figuring out how to get a nice list of colours and descriptions to show under the additional information tab – which I’ve just managed and need to prettify a bit.
The relevant section of my code is at the bottom of my post (I think I’ve got a few statements that don’t do anything useful to prune, still). This bit, though, about two thirds through is the key bit for getting only relevant colours rather than all colours:
if ( ! in_array( $term_name, $values ) )
continue;
I’ll take a look for the image section soon. I pulled the interesting bits for this mostly from $woocommerce/templates/single-product/add-to-cart/variable.php . Somewhere in $single-product/ probably exists the image loading code, and somewhere in that would be my first guess location for the useful code – though what is there may be a call to a function that exists elsewhere. That function may be all you need, though.
Now that I’ve seen what you are trying to do I want it too, but it’ll probably be an hour or two before I get back to looking. With my (very) limited PHP experience I’m shooting in the dark a bit.
Tor
if ( $attribute['name'] == 'pa_color' ) {
echo "<dl>";
$args = array( 'orderby' => 'name', 'hide_empty' => false, 'menu_order' => false );
$terms = get_terms( 'pa_color', $args );
$values = woocommerce_get_product_terms( $product->id, $attribute['name'], 'names' );
foreach ( $terms as $term ) :
$term_name = $term->name;
if ( ! in_array( $term_name, $values ) )
continue;
$term_desc = $term->description;
echo "<dt>$term_name <dd> $term_desc";
endforeach;
echo "</dl>";
}