if i’m not totally mistaken you can configure woocommerce that way
-shop
–category1
—product1.1
—product1.2
–category2
—product2.1
—product2.2
without any coding and very easy from your wordpress backend, take a look at:
“woocommerce>settings>catalog”