prayas prayas - 3 days ago 7
PHP Question

Fetch child products in grouped products woocommerce

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.

Answer

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.

Comments