Skip to content

Instantly share code, notes, and snippets.

@leewillis77
Created October 5, 2020 13:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leewillis77/efcea448952fbe468a3ea83dfd875f55 to your computer and use it in GitHub Desktop.
Save leewillis77/efcea448952fbe468a3ea83dfd875f55 to your computer and use it in GitHub Desktop.
Exclude multiple categories from Google Product Feed
<?php
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' ) );
// Exclude products in category ID 21
if ( in_array( 21, $cats ) ) {
return TRUE;
}
// Exclude products in category ID 22
if ( in_array( 22, $cats ) ) {
return TRUE;
}
// Exclude products in category ID 23
if ( in_array( 23, $cats ) ) {
return TRUE;
}
// If not in the above categories use the default behaviour.
return $excluded;
}
add_filter( 'woocommerce_gpf_exclude_product', 'lw_gpf_exclude_product', 11, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment