Auto-Sync Product Categories Menu WordPress Function
What it does?
-
Auto-rebuilds on taxonomy changes – Listens to product category create/edit/delete events and regenerates a dedicated menu (creates it if missing).
-
Mirrors the full hierarchy – Recursively adds parent and child categories so the menu structure matches your catalog.
-
Skips empty subcategories – Avoids dead ends by excluding child categories with no products, while still allowing empty top-level parents.
-
Prevents duplicates – Clears existing items before rebuilding to keep the menu clean.
-
Daily safety refresh – Schedules a once-per-day cron run as a fallback to catch any missed updates.
Why it’s useful?
-
Zero maintenance – Stop hand-editing menus every time categories change; updates happen automatically.
-
Better UX & navigation – Customers see an accurate, uncluttered category tree with working links at all times.
-
Fewer dead ends – Hiding empty subcategories reduces bounce and confusion.
-
Operational resilience – The daily refresh ensures the menu stays correct even after imports, migrations, or missed hooks.
