It is necessary to get the value from the array with the key [0], but the array is in the object. How can I put it in a variable?
WC_Product_Variable Object
You do not have access to this object because it is protected.
In your case, try to call the method get_children()
.
WC_Product_Variable::get_children(0);
To get the children variation Ids for a variable product, use WC_product get_children() method (that doesn't have/allow any arguments):
// (if needed) Get an instance of the WC_product object (from a dynamic product ID)
$product = wc_get_product($product_id);
// Get children product variation IDs in an array
$children_ids = $product->get_children();
// Get the first ID value
$children_id = reset($children_ids);
// or
$children_id = $children_ids[0];
Tested and works.