Show stock status next to each attribute value in WooCommerce variable products

Viewed 3898

I want to implement in my store something similar like this:

enter image description here

I have this code, but this show quantity next to each variation.

function get_stock_variations_from_product(){
global $product;
$variations = $product->get_available_variations();
foreach($variations as $variation){
     $variation_id = $variation['variation_id'];
     $variation_obj = new WC_Product_variation($variation_id);
     $stock = $variation_obj->get_stock_quantity();
}
}

And also this code:

  global $product;
$product_variations = $product->get_available_variations();

foreach ($product_variations as $variation)  {
    $var_data = $variation['attributes'];
    $var_data['in_stock'] = $variation['is_in_stock'];
}

//List all attributes with stock available or not array..
echo '<pre>';
print_r($var_data);
echo '</pre>';
die;

How can I customize the variable products to show stock Status next to each attribute values?

Thanks

1 Answers
Related