Get children of a grouped product

Here is a simple example.

/**
 * Test creating a new grouped product.
 *
 * @since 2.7.0
 */
function test_grouped_product_create()
{
    $simple_product = WC_Helper_Product::create_simple_product();
    $product = new WC_Product_Grouped();
    $product->set_children(array($simple_product->get_id()));
    $product->set_name('My Grouped Product');
    $product->save();
    $read_product = new WC_Product_Grouped($product->get_id());
    $this->assertEquals('My Grouped Product', $read_product->get_name());
    $this->assertEquals(array($simple_product->get_id()), $read_product->get_children());
}

 

Leave a Reply