I have write a little snippet to get all size product variation color and specific quantity in my product page And I have this result :
color 1 size S = quantity
Color 1 size M = quantity
Color 1 size L = quantity
Color 2 size M = quantity
Color 2 size L = quantity
...
And I would like a result more like that
Color 1 : quantity of size S, quantity of size M, quantity of size L
Color 2 : quantity of size S, quantity of size M, quantity of size L
...
how can I show this result ?
This is my code:
add_action( 'woocommerce_before_variations_form', 'get_selected_variation_stock' );
function get_selected_variation_stock() {
global $product;
if ($product->is_type( 'variable' ) && has_term( 71 , 'product_cat' ))
{
echo 'Taille(s) proposée(s) '.'</br>';
$avail_vari = $product->get_available_variations();
foreach ($avail_vari as $key => $value)
{
$vari_id = $value['variation_id'];
$vari_color = $value['attributes']['attribute_pa_couleur'];
sort($vari_color);
$vari_taille = $value['attributes']['attribute_pa_taille'];
sort($vari_taille);
$vari_obj = new WC_Product_variation($vari_id);
$vari_stock = get_post_meta( $vari_id, '_booking_lockout_field',true );
$sum+= $vari_stock;
if ( $vari_stock > 0 ) {
echo $vari_color . " en " . $vari_taille . " : " . $vari_stock . " ".'</br>';
}
}
echo 'Soit un total de : ' . $sum .' costume(s) disponible'.'</br>';
}
}