看看我能不能幫到你。 我認為你可以做的是使用 PHP OR 運算符,它基本上是兩個管道“||”。 OR 運算符通過組合條件來工作,然后如果至少有一個條件為真,則 PHP 執(zhí)行 if 塊。如果兩個條件都為 false,則 PHP 不會執(zhí)行 if 塊語句。 當然,如果您有很多屬性,可能有更有效的方法來做到這一點,但我希望這會有所幫助!
還請記住確保導(dǎo)航菜單中所需的屬性已存檔。您可以通過轉(zhuǎn)到產(chǎn)品 -> 屬性,然后將鼠標懸停在屬性上并單擊“編輯”來完成此操作。在編輯屏幕上,確保選中“啟用存檔”復(fù)選框。
以下是該函數(shù)的示例:
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; }