How to register multiple taxonomies for Woocommerce custom attributes?
P粉610028841
P粉610028841 2023-09-03 21:18:04
0
1
476
<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粉610028841
P粉610028841

reply all(1)
P粉428986744

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;
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!