I am using Woocommerce with the Woocommerce Composite Products extension (Which allows you to make a product out of a combination of other products).
I am trying to figure out if a composite product is 'in stock', but the usual function is_in_stock() doesn't work on composites.
If there is a more appropriate function, I would like to know what it is.
Alternatrively, The function 'wc_get_product()' below returns the below, including componentproduct IDs (assigned_ids):
$product = wc_get_product($productid);
var_dump($product);
Returns:
object(WC_Product_Composite)#11305 (23) {
["extended_data":"WC_Product_Composite":private]=>
array(7) {
["add_to_cart_form_location"]=>
string(7) "default"
["shop_price_calc"]=>
string(7) "default"
}
["composite_meta":"WC_Product_Composite":private]=>
array(4) {
[1477435352]=>
array(19) {
["component_id"]=>
string(10) "1477435352"
["query_type"]=>
string(11) "product_ids"
["assigned_ids"]=>
array(2) {
[0]=>
int(541)
[1]=>
int(588)
}
}
}
Basically, what I want is to extract and loop through the 'assigned_ids' subarray checking if each is in stock, but aside from printing this to the screen, I'm unable to access this object's properties because they are 'private' (something I'm completely unfamiliar with). I believe I can possibly figure this out by hunting down the class in Wordpress / the plugin files but I have no idea how to find it. Any help would be much appreciated.
Accessing the data:
As you can see, to get the
WC_Product_Composite
object protected properties, you should need to use the inheritedWC_Product
methods or more specificallyWC_Product_Composite
methods documented in the core code class.Now, The easiest way to access (unprotected) data is to use the following methods inherited from
WC_Data
Class:Or you could use also some
WC_Product_Composite
methods as:Any way you will need to get into core files code to understand how things works and to get the right methods for Composite products.