<?php
$product = wc_get_product( get_the_ID ());
$variation_data = array();
if ( $product->is_type( 'variable' ) ) {
$variations = $product->get_available_variations();
foreach ( $variations as $variation ) {
$attributes = $variation['attributes'];
$image_id = $variation['image_id'];
$image_url = wp_get_attachment_image_src( $image_id, 'full' );
$image_url = $image_url[0];
$image_thumb = wp_get_attachment_image_src( $image_id, 'thumbnail' );
$image_thumb = $image_thumb[0];
$attribute_values = array_values( $attributes );
$variation_data[] = array(
'attribute_value' => $attribute_values,
'image_url' => $image_url,
'thumb_img' => $image_thumb
);
}
usort( $variation_data, function( $a, $b ) {
return $a['variation_id'] - $b['variation_id'];
});
}
$tallas ="";
?>
<section style="display:none">
<?php
for($i=0; $i<sizeof($variation_data); $i++){
$atributoTalla =$variation_data[$i]['attribute_value'][0];
$atributoColor =$variation_data[$i]['attribute_value'][1];
$varImagen =$variation_data[$i]['image_url'];
$varThumb = $variation_data[$i]['thumb_img'];
if (strpos( $tallas, $atributoTalla."," ) === false) {
$tallas .= $atributoTalla. ",";
}
echo "<p id='".$atributoTalla.$atributoColor."'data-var_imagen =".$varImagen." data-var_thumb =".$varThumb."></p>";
}
?>
<div id="data-tallas"><?php echo $tallas; ?></div>
</section>