I’ve been searching and using the Woocommerce documentation, but cannot get a custom attribute in my menu. I used the following code:
add_filter('woocommerce_attribute_show_in_nav_menus', 'wc_reg_for_menus', 1, 2);
function wc_reg_for_menus( $register, $name = '' ) {
if ( $name == 'pa_merk' ) $register = true;
return $register;
}
I am unable to select this custom attribute in my menu manager in WordPress. Can anyone help?
I had similar issue.
Problem:
Created a custom field under the ‘General’ tab using the guide below
http://www.remicorson.com/mastering-woocommerce-products-custom-fields/
Couldn’t reference the custom field and make it a menu option. This was due to there being no associated archive template so output could not be rendered.
Solution:
The key to this working is creating an attribute with ‘Enable Archives?’ being checked. This associates the attribute with the archive template.
http://kb.oboxthemes.com/themedocs/store-content-archives/
WordPress archive index
http://codex.wordpress.org/Creating_an_Archive_Index
Its an explicit, multi-step process so bear with me.
Overview:
To start with I removed my custom field as it’s not going to work as intended.
Create an attribute and options
Add the attribute to your product
Add the necessary code to functions.php
In your (child) functions.php add your add_filter() method and function as above referencing your attribute slug ‘sizes’ with ‘pa_sizes’ (prefix with pa_)
http://docs.woothemes.com/document/using-custom-attributes-in-menus/
Create a new menu
Add a menu item
Add attribute options
Now refresh your frontend and the menu link ‘Sizes’ should be there with a dropdown of the options.
Create custom archive template
Instructions to create a different template per attribute menu item can be found here:
http://docs.woothemes.com/document/using-custom-attributes-in-menus/
Hope this helps