// ======= (pega esto dentro de tu plugin actual; por ejemplo al final) ======= // Menús por sede (IDs de Apariencia → Menús) const TGH_MENU_MAINSTORE = 0; // ← PON AQUÍ el ID del menú para main_store (ej. 10641) const TGH_MENU_SANDBAR = 0; // ← PON AQUÍ el ID del menú para sandbar (ej. 10642) /** * Forzar el menú mostrado según la cookie `selected_store`. * Aplica tanto a temas que usan theme_location (primary/header) * como a Elementor Nav Menu (que internamente usa wp_nav_menu()). */ add_filter('wp_nav_menu_args', function ($args) { // Evitar en admin/editores if (is_admin()) return $args; // Si no definiste menús, no tocamos nada if (!TGH_MENU_MAINSTORE && !TGH_MENU_SANDBAR) return $args; // Detectar store actual $store = tgh_store_get_current(); if (!$store) return $args; // Resolver menú por sede $menu_id = null; if ($store === 'main_store' && TGH_MENU_MAINSTORE) { $menu_id = (int) TGH_MENU_MAINSTORE; } elseif ($store === 'sandbar' && TGH_MENU_SANDBAR) { $menu_id = (int) TGH_MENU_SANDBAR; } if (!$menu_id) return $args; // Opcional: limitar a ciertas ubicaciones del theme // Si quieres que SOLO cambie en el menú principal, descomenta: // $location = isset($args['theme_location']) ? $args['theme_location'] : ''; // $is_primary_like = in_array($location, ['primary','header','main','menu-1','nav-menu'], true); // if (!$is_primary_like && empty($location)) { /* Elementor suele venir sin theme_location */ } // En la práctica, forzamos siempre el menú: $args['menu'] = $menu_id; // Esto asegura que aunque el template/Elementor haya fijado otro menú, // prevalezca el que corresponde a la sede. return $args; }, 100); /** * (Opcional) Si tu theme usa ubicaciones registradas y quieres fijar * la asignación a nivel de "location", puedes mapear aquí. * Úsalo solo si tu theme depende fuertemente de theme_location. */ add_filter('theme_mod_nav_menu_locations', function ($mods) { if (is_admin()) return $mods; if (!is_array($mods)) $mods = []; $store = tgh_store_get_current(); if (!$store) return $mods; $menu_id = null; if ($store === 'main_store' && TGH_MENU_MAINSTORE) { $menu_id = (int) TGH_MENU_MAINSTORE; } elseif ($store === 'sandbar' && TGH_MENU_SANDBAR) { $menu_id = (int) TGH_MENU_SANDBAR; } if (!$menu_id) return $mods; // Lista de ubicaciones típicas a forzar (ajusta según tu theme) $locations_to_force = ['primary', 'header', 'menu-1', 'main']; foreach ($locations_to_force as $loc) { if (isset($mods[$loc]) || array_key_exists($loc, $mods)) { $mods[$loc] = $menu_id; } } return $mods; }, 10);