Subcategories not working when using shared base with custom taxonomy

Đã có trọn bộ đề thi thử THPT Quốc Gia 2022 các môn: vip.dethihsg247.com

I have a custom URL structure for my WooCommerce setup.
Essentially, I have a custom taxonomy (pwb-brand) with the same base as the default (product_cat) taxonomy. To make pagination for both product categories and brands work, I used a piece of code to help WordPress distinguish brands from product categories. This works, but creates a situation where nested categories pages return a 404. To illustrate, site.com/catalog/brand and site.com/catalog/category work fine, pagination included, but site.com/catalog/category/subcategory returns a 404.
Here’s the code:

How do I modify it to account for subcategories or skip checking subcategory queries altogether (because brands have no nested terms)?
I’m a noob with PHP. Please explain like I’m 5.
Thank you!

Xin chào các bạn và quý Thầy Cô. Hãy nhập từ khóa mình muốn vào ô tìm kiếm trên Website để tìm kiếm mọi thứ hoặc trên google các bạn hãy nhập từ khóa + dethihsg247.com để tìm kiếm các bài viết của chúng tôi nhé.
  • Hiện tại chúng tôi có hơn 25 nghìn bài văn mẫu các thể loại.
  • Kho tài liệu, đề thi học sinh giỏi các lớp vô cùng phong phú.
  • Mỗi ngày cập nhật hơn 100 đề thi chất lượng từ các website bán tài liệu lớn.

Tải đề thi VIP với giá siêu rẻ tại Vip.Dethihsg247.Com