1
votes

For a special gallery i need to show all woocommerce variation images. On the woocommerce content-single-product.php i can access the variations but i cant get the image url out of it. How can i do that?

Inside my content-single-product.php overwrite:

<?php

    $args = array(
        'post_type'     => 'product_variation',
        'post_status'   => array( 'private', 'publish' ),
        'numberposts'   => -1,
        'orderby'       => 'menu_order',
        'order'         => 'asc',
        'post_parent'   => $post->ID 
    );

    $variations = get_posts( $args ); 

    echo "<pre>"; print_r($variations); echo "</pre>"; 

?>
1

1 Answers

0
votes

You can do something like this.

$product = new WC_Product_Variable( $product_id );
// get the product variations
$product_variations = $product->get_available_variations();

if ( !empty( $product_variations ) ) {
    foreach($product_variations as $product_variation) {
        echo $product_variation['image_src'];
    }
}