感谢@SallyCJ给出了正确的答案—您可以将类别ID/slug/名称的数组提供给is_tax()
检查多个类别。以下是正确的代码:
/* Hyde out of stock product specific category */
add_filter( \'pre_get_posts\', \'hide_out_of_stock_from_cat\' );
function hide_out_of_stock_from_cat( $query ) {
if ( $query->is_tax( \'product_cat\', array( 15, 16, 18, 19, 20, 21, 22, 23, 24, 59, 60, 62, 63, 66 ) ) && $query->is_main_query() ) {
$query->set( \'meta_query\', array(array(
\'key\' => \'_stock_status\',
\'value\' => \'outofstock\',
\'compare\' => \'NOT IN\'
)));
}
}