以下PHP代碼不包括Google Merchant Center中的Woocommerce類別。你如何結合in_array
來縮短代碼?在PHP中組合多個陣列
// Exclude categories from my Google Product Feed
function lw_gpf_exclude_product($excluded, $product_id, $feed_format) {
// Return TRUE to exclude a product, FALSE to include it, $excluded to use the default behaviour.
$cats = wp_get_post_terms($product_id, 'product_cat', array('fields' => 'ids'));
if (in_array(60, $cats)) {
return TRUE;
}
if (in_array(63, $cats)) {
return TRUE;
}
if (in_array(88, $cats)) {
return TRUE;
}
if (in_array(89, $cats)) {
return TRUE;
}
return $excluded;
}
add_filter('woocommerce_gpf_exclude_product', 'lw_gpf_exclude_product', 11, 3);
[http://php.net/manual/en/function.array-intersect.php](http://php。淨/手動/ EN/function.array-intersect.php) – cske