Custom WooCommerce rewrite rules with comma delimiter

I'm trying to troubleshoot a wide-scale problem.

I'd like to rewrite default WooCommerce permalinks for categories, to delimiter as commas. Let's take an example:

  • Brand
    • Model
      • Generation
        • Engine
          • Product

The permalink structure I'd like to have:

  • /chip-tuning-Ford
    • /chip-tuning-Ford-Focus
      • /chip-tuning-Ford-MK3-FL
        • /chip-tuning-Ford-MK3-FL-1.5TDCi-75kW
          • /chip-tuning-Ford-MK3-FL-1.5TDCi-75kW-Basic-Box

I did this via generate_rewrite_rules action, but currently, we have about 4000 categories and 9000 products, so each combination takes a lot of time and space. All rewrite rules by WP default are saved into one field on the DB, so it makes the website very slow.

Also, I tried dynamic rules, but it works fine for 1-3 levels and if category names don't have an additional delimiter - replaced by space.

The general problem is how to write a dynamic rewrite rule to match a certain category and product. The generator is already written, need a way to save / store / handle it.

FYI. Categories and products are created via Rest API.

Thanks for your advice!

Topic woocommerce-offtopic rewrite-rules url-rewriting permalinks Wordpress

Category Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.