php - Woocommerce, get main product id

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!
Answer
Solution:
You can get the parent id from a variation like this for example..
$main_product_id = $variation->get_parent_id();
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: script cache:clear returned with error code 255
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.