WooCommerce attributes – replace selection field with variation images

Question

I have a variation field(pa_printing-position) with attributes like “front”, “back”, etc. and I want to replace the selection field in single product with the variation image of the current product.

I know that there are many plugins that can do this job (variation swatches) but i want to display the image of the current product, not the same image for the attribute “front”.

I’ve managed to display the variation images of the current product with this code but i can’t make it like selection field

if ( $product->has_child() ) {

$variations = $product->get_children();

    foreach ( $variations as $variation ) {

        if ( has_post_thumbnail( $variation ) ) {

            echo get_the_post_thumbnail( $variation );
        }
    }
}

The result i want is something like this

enter image description here

0
, , Billy 2 years 2020-09-02T04:10:28-05:00 0 Answers 50 views 0

Leave an answer

Browse
Browse