So one of our clients uses an ERP in order to update the products of woocomerce in his wordpress website. The ERP is updating the database directly for everything regarding the products,categories,subcategories etc. Their only issue is that they want to create a menu item at the main menu and when they add a new category/subcategory or remove an existing to dynamically update that menu_item that will hold the product categories/sub-categories.
Is there any function that renders ALL the product categories as menus because the code I started implementing seems way an overkill.
require_once('../../../wp-config.php');
require_once('ProductToMenu.php');
global $wp_query;
global $wpdb;
$productToMenuHelper = new ProductToMenu();
$activeTemplateResult = $wpdb->get_results("SELECT * FROM `wp_options` where option_name="template"");
$activeTemplate = $activeTemplateResult[0]->option_value;
$templateOptionsResult = $wpdb->get_results("SELECT * FROM `wp_options` where option_name="theme_mods_".$activeTemplate.""");
$templateOptions = $productToMenuHelper->unserializeOption($templateOptionsResult[0]->option_value);
$mainMenuId = $templateOptions["nav_menu_locations"]["top"];
$menuItems = $wpdb->get_results("SELECT p.*
FROM wp_posts AS p
LEFT JOIN wp_term_relationships AS tr ON tr.object_id = p.ID
LEFT JOIN wp_term_taxonomy AS tt ON tt.term_taxonomy_id = tr.term_taxonomy_id
WHERE p.post_type="nav_menu_item" and tt.term_id={$mainMenuId}");
var_dump($menuItems);
What Im trying to do is find the main menu from template, find all the menu items of that menu and after that get a payload of all product categories and subcategories and check if exist in the menu items payload