Add WooCommerce attributes Into Nav Menus

While setting up an online store for a client, we needed to list product attributes in the menu. To take advantage of showing the current page feature of the menus (to show current page as highlighted), I didn’t want to have to manually add custom links for each attribute.

The client had 150+ attributes so I wanted to be able to select, reorder and add the attributes without having to write out all the custom links separately.

So there is a handy filter we can add to your themes’ functions.php file or via a small plugin like this:

add_filter('woocommerce_attribute_show_in_nav_menus','wc_reg_for_menus', 1, 2);
function wc_reg_for_menus( $register, $name = '' ) {
     if ( $name == 'colors' ) $register = true;
     return $register;
}

In the above example, I am using the attribute ‘colors’ which will add it to the nav menus system in WordPress, so you can add all attribute values into your menus.

Useful post? Share it

One comment on “Add WooCommerce attributes Into Nav Menus

  1. Hi. This is exactly what I am needing to do, however, adding the PHP into a snippet plugin or adding it directly into the functions.php file are not working. My attribute slug is “state.”

    Any ideas?

Leave a Reply

Your email address will not be published.