How to Get Parent Product ID in Magento 2

The post shows the programmatic method to get parent product ID in Magento 2. Magento 2 has 3 product types named configurable, bundled and grouped, those have children products. You might be wondering if you can get parent product ID of these 3 product types.

You can use the solution if you are selling the store products on 3rd party platforms like Facebook shop and care to enhance the shopping journey.

For example, I used the below method for a client who wanted to redirect the customers to the website directly on the cart page from Facebook shop product. And the product had to be already added to the cart. The customer can skip the step to manually add the product to the cart in the Magento 2 store. However, to implement it, I needed to get the parent product ID as the simple product configuration can’t be displayed.

Hence, the solution:

Method to Get Parent Product ID in Magento 2:

That’s it.

Mention your doubts in the Comments section below and I’d be happy to solve them for you.

Feel free to share the post with fellow developers on social media.

Thank you.

(based on 6 Reviews)
How to Get Parent Product ID in Magento 2Author Magento Badge

Sanjay Jethva

Sanjay is a co-founder at Meetanshi. He is a Certified Magento Developer who loves creating Magento E-commerce solutions. Owing to his contributions in Magento Forums and posting solutions, he is among the top 50 contributors of the Magento community in 2019. When he is not engrossed with anything related to Magento, he loves to play cricket.


  • James

    Getting this error with it: Parse error: syntax error, unexpected ‘getParentId’ (T_STRING), expecting function (T_FUNCTION) or const (T_CONST) in /chroot/home/a2bf3fe2/ on line 20

  • Magno

    It seems to don’t work. I’m trying with a bundled product and I’m getting an empty array as described here:

    Was this already fixed?

    • Sanjay Jethva

      Hello Magno,
      Please try this:

      Thank You

Leave a Reply

Your email address will not be published. Required fields are marked *