I want to fetch child product ids of a parent grouped product, how to do that,
earlier woocommerce saves the child array in wp_option
table as key to be _transient_wc_product_children_ids_8
but the recent update has changed the way it saves to the database, plz help me, how can I fetch child products from parent product in grouped products.
Use the get_children()
method in the WC_Product_Grouped
class.
$product_id = 8; // ID of parent product
$product = get_product( $product_id );
$children = $product->get_children();
It should return an array of product IDs.
UPDATED for WooCommerce 2.5+
Replaces get_product()
with wc_get_product()
$product_id = 8; // ID of parent product
$product = wc_get_product( $product_id );
$children = $product->get_children();
On Woocommerce version 2.5.0 get_product is already deprecated.
Use wc_get_product instead
$product_id = 8;
$product = wc_get_product($product_id);
$product->get_children();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With