You can add a WordPress menu to WooCommerce pages via PHP by registering a custom menu location in the WordPress dashboard and echoing it with wp_nav_menu() hooked into a WooCommerce content action, giving shop, cart, or checkout pages a secondary navigation (like a category menu) that your theme doesn’t include by default.
Why Add a Custom Menu to WooCommerce Pages
- Show a product category navigation menu above the shop content
- Add a secondary utility menu (support links, size guide) on WooCommerce pages specifically
- Manage the menu’s items through the standard Appearance → Menus screen instead of hardcoding links
Step 1: Create the Menu in the Dashboard
Go to Appearance → Menus, create a new menu (e.g. “Shop Categories”), and add your product category links to it. You don’t need to assign it to a theme location — this menu will be called directly by name in code.
Step 2: Output the Menu on WooCommerce Pages
/** Print the "Shop Categories" menu above the main WooCommerce content */
add_action( 'woocommerce_before_main_content', 'render_shop_categories_menu', 15 );
function render_shop_categories_menu() {
wp_nav_menu( array(
'menu' => 'Shop Categories',
'container_id' => 'shop-categories-nav',
'fallback_cb' => false,
) );
}

The fallback_cb => false setting prevents WordPress from printing a default page list if the menu doesn’t exist yet or its name is mistyped.
Troubleshooting
PHP Error Referencing an Unrelated Theme Function
If adding this snippet triggers an unrelated fatal error mentioning a theme-specific function, that’s a sign the theme’s custom CSS/style generation is conflicting with a change elsewhere in functions.php — check for a duplicate function name or a missing closing brace introduced nearby, rather than assuming the menu snippet itself is at fault.
Menu Doesn’t Appear At All
Double-check the menu name in the snippet exactly matches what you typed in Appearance → Menus — wp_nav_menu() matches by name (or slug/ID) and silently outputs nothing on a mismatch when fallback_cb is disabled.
Menu Shows on Every Page, Not Just WooCommerce Ones
The hook used above (woocommerce_before_main_content) only fires on WooCommerce template pages, so this shouldn’t happen — if it does, confirm no other code is also calling wp_nav_menu() with the same menu on a different hook.
Frequently Asked Questions
Do I need to assign the menu to a theme location?
No — calling it directly by name via wp_nav_menu() bypasses the need for a registered theme location.
Can I use a menu ID instead of its name?
Yes — pass the numeric menu ID as the menu argument instead of its name string.
Will this show on the cart and checkout pages too?
woocommerce_before_main_content fires on all core WooCommerce templates, including cart and checkout, unless you add a conditional to limit it to specific pages.
Conclusion
Adding a WordPress menu to WooCommerce pages via PHP is a two-step process: create the menu in the dashboard, then print it with wp_nav_menu() hooked into a WooCommerce content action. Keep an eye on unrelated theme conflicts if a fatal error appears after adding the snippet.
See also How to Rename the My Account Menu Label When Logged Out. Then read How to Make the WooCommerce My Account Navigation Menu Horizontal.
Prefer no code? All-in-One Utilities Woo Add-on adds over 50 WooCommerce features, so you can switch them on without code.