I want to implement in my store something similar like this:
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
You can do it using a custom function hooked in
woocommerce_variation_option_name
filter hook. This is only viable for products that have a unique attribute for their variations…Here is the code:
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
You will get this (for example):