search

Home  >  Q&A  >  body text

How to register multiple taxonomies for Woocommerce custom attributes?

<p>I've been using the Woocommerce docs to get custom attributes in my WordPress navigation menu: </p> <p>https://woocommerce.com/document/using-custom-attributes-in-menus/</p> <p>I used the following code: </p> <pre class="brush:php;toolbar:false;">add_filter('woocommerce_attribute_show_in_nav_menus', 'wc_reg_for_menus', 1, 2); function wc_reg_for_menus( $register, $name = '' ) { if ( $name == 'pa_druivensoort' ) $register = true; return $register; }</pre> <p>This works, but how should I modify the code to register multiple custom taxonomies? </p>
P粉610028841P粉610028841448 days ago523

reply all(1)I'll reply

  • P粉428986744

    P粉4289867442023-09-04 18:08:46

    See if I can help you. I think what you can do is use the PHP OR operator which is basically two pipes "||". The OR operator works by combining conditions and then if at least one condition is true, PHP executes the if block. If both conditions are false, PHP will not execute the if block statement. Of course, if you have a lot of properties, there may be more efficient ways to do this, but I hope this helps!

    Also remember to make sure the required properties in the navigation menu are archived. You can do this by going to Product -> Properties, then hovering over the property and clicking "Edit". On the edit screen, make sure the "Enable archiving" checkbox is selected.

    The following is an example of this function:

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

    reply
    0
  • Cancelreply