Reputation: 25
I'm currently working on a WooCommerce plugin and attempting to get main product id from variable product.
If product has no variations i will use:
$product_id = $product['data'] -> get_id();
and it works.
But if I have product with variations i have problem to get main id (not id of variable product)
e.g.
Product id=10 has 2 variations with IDs 11 and 12, and if i add to cart product with id 12 i wanna get id of main product (id = 10).
I searched for an answer for a long time, but found nothing useful, so I turn here.
I appreciate any help!
Upvotes: 1
Views: 734
Reputation: 1524
You can get the parent id from a variation like this for example..
$main_product_id = $variation->get_parent_id();
Upvotes: 1