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


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

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

If I select both of them:

Can you help me with this?

Thanks a lot!