Home » WooCommerce: Add WP Menu to WC Pages via PHP

WooCommerce: Add WP Menu to WC Pages via PHP

by adminkys

It’s pretty easy to add another custom menu to your WooCommerce pages via PHP. For example, you might want to add a list of Product Category links, and manage this through the default “Appearance > Menu” in the WordPress dashboard.

WP Dashboard > Appearance > Menu: create a new menu

Create a new menu called “Categories” and add the product categories you wish to it.

Create a new menu in WordPress

PHP Snippet: Add WP menu to WooCommerce pages

/**
 * @snippet       Add WP menu to WooCommerce pages
 * @how-to        Get tutoraspire.com FREE
 * @sourcecode    https://tutoraspire.com/?p=22012
 * @author        Tutor Aspire
 * @testedwith    WooCommerce 2.5.2
 */

add_action( 'woocommerce_before_main_content', 'tutoraspire_echo_categories_menu' );

function tutoraspire_echo_categories_menu() {
wp_nav_menu( array( 'menu' => 'categories', 'container_id' => 'nav_menu-2' ) );
}

You may also like