Need to show category and subcategory of a product in the URL

Hello!

I have products that have a parent and a child category and I want to have the URL like this:

domain.com/shop-slug/parent-category/child-category/product-name

But, when I select the child category only, wordpress only shows that one in the URL:

domain.com/shop-slug/child-category/product-name

If I select both of them:

domain.com/shop-slug/parent-category/product-name

Can you help me with this?
Thanks a lot!