WooCommerce – list products AND subcategories together in a-z order. Possible?

in a website i am creating (not live yet) i have products in a main category. I also have subcategories that have other products in them.

I know that WooCommerce can display subcategories and products on the same page, but the subcategories are always listed first.

I have used the code at https://wordpress.org/support/topic/category-display-show-subcategories-products-excluding-subcategory-products/ which stops the cubcategories products from being listed in the main products page, but is there a way of mixing the subcategories and main category products so that they are all in a-z title order (like below)?

Shirts (category)

enter image description here

As you can see, ‘Just a shirt’ & ‘Sports shirt’ are only in the main shirts category, not a subcategory, but i would like those (and all other products not in a subcategory) included in the full list of subcategories, in a-z order.

(another way of saying it is having the subcategories listed with the products)

The same would happen when you enter a subcategory, it would show the subcat products, along with any sub-subcategories, and so on…

I’ve seen this on a few websites, but can’t find any code to do it. Is that possible in WooCommerce?
Also i would like to have this in the main loop, and in the sidebar.

Thanks in advance for any help.