As you know when we works with any customization work related to configurable product and simple product, we need some code snippet that helps us to find out the relation between parent and child product.

Lets take one example, when we have one simple product (child product) and we need all the simple (child) product associated with its parent product. In this case we require solution that gives us Parent product id and using this parent product we are able to find all its simple (child) products.

In order to get the parent product id in Magento 2, you can use below code at any file.

If you want to use this code at block file in Magento 2, then use below code snippet.

That’s it.