Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

How to get stock quantity of each variable product? WordPress


I searched on internet but found no answer for this question :(

For Simple product, We normally use $product->get_stock_quantity() to get product quantity of that product.
If I use $product->get_stock_quantity() for variable product, it will return
quantity of product on parent level.

The thing is I would like to get stock quantity of each variable product.

For Example:
Shirt has Red , Blue for variable product.

Red Shirt x3
Blue Shirt x4

I want that if I use Select box to select Red, Product page will show 3 in stock.
and if I use Select box to select blue, it will show 4 in stock.

Please help me.

Answers (2)


Reigel Gallarde answers:

I have not tested this, but I believe it should be something like this...

$variables = $product->get_children();
foreach ( $variables as $variable ) {
// $variable->get_stock_quantity();

Reigel Gallarde comments:

let me know if something like this is what you want...
[[LINK href=""]][[/LINK]]

akenarong999 comments:

Yes, it is somethings like this.

Reigel Gallarde comments:

it is available by default...

try doing this settings...