Custom Woocommerce Menu

Hi :slight_smile:

I am attempting to create a custom woocommerce menu to display in the ‘main menu’ location on all woocommerce pages.

So far the code below works well. The only problem is that the custom menu is not only displaying in the ‘/main menu’ location but also in the ‘footer’ menu location.

I have created a ‘footer’ menu within the admin -> Appearance -> Menu assigned to the ‘footer’ menu location.

Why does the custom menu using the code below override the global footer menu?

How can I make sure the custom woocommerce menu only displays within the ‘main menu’ location only?

// Custom Woocommerce Menu
    function woocommerce_menu( $args ) {
        if ( is_shop() || is_product() || is_cart() || is_checkout() || is_account_page() ) {
        $args['theme_location'] = 'primary';
        $args['menu'] = 'woocommerce';
          }
         return $args;
    }
add_filter( 'wp_nav_menu_args', 'woocommerce_menu' );

// Register custom menu
register_nav_menus ( array(
    'woocommerce' => __( 'Woocommerce Menu', '__x__' )
	) 
);

Thanks :slight_smile: :slightly_smiling_face:

Hello @christiaan001,

Thanks for writing in! The register_nav_menus() function registers navigation menu locations for a theme. Therefore, the location in your code should be:
$args['theme_location'] = 'woocommerce';

For reference:

Hope this helps.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.