Skip to content

Instantly share code, notes, and snippets.

@HenriqueSilverio
Created January 8, 2019 17:09
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 HenriqueSilverio/ef7b3a1a0de8b416a59123cbecb0dfb5 to your computer and use it in GitHub Desktop.
Save HenriqueSilverio/ef7b3a1a0de8b416a59123cbecb0dfb5 to your computer and use it in GitHub Desktop.
<?php
function getChildrenProducts()
{
$productId = get_the_ID();
$product = wc_get_product($productId);
$childrenIds = $product->get_children();
if (empty($childrenIds)) {
return [];
}
$children = wc_get_products([
'include' => $childrenIds,
]);
if (empty($children)) {
return [];
}
return $children;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment