Permalinks: custom post type -> custom taxonomy -> custom sub taxonomy -> post

you can try with this plugin (or see its code)

https://wordpress.org/plugins/wp-better-permalinks/

It allows you change the custom friendly permalinks structure to Custom Post Type > Taxonomy > Post and Custom Post Type > Taxonomy instead of default WordPress structure.
it Provides different permalinks structure pattern:
Custom Post Type > Single Term (or Term tree) > Post
Custom Post Type > Post (when no term is selected)
Custom Post Type > Single Term (or Term tree)

It helped me a lot with this issue…