Skip to content

Instantly share code, notes, and snippets.

@sirwan
Created August 23, 2018 20:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sirwan/4b808b347cec264d0fdd3de659bc32e0 to your computer and use it in GitHub Desktop.
Save sirwan/4b808b347cec264d0fdd3de659bc32e0 to your computer and use it in GitHub Desktop.
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());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment