Skip to content

Instantly share code, notes, and snippets.

@leewillis77
Created December 3, 2018 11:32
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/b126167de7f136e0a32ebd39346cbe98 to your computer and use it in GitHub Desktop.
Save leewillis77/b126167de7f136e0a32ebd39346cbe98 to your computer and use it in GitHub Desktop.
Exclude categories from the 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' ) );
if ( in_array( 21, $cats ) ) {
return TRUE;
}
return $excluded;
}
add_filter( 'woocommerce_gpf_exclude_product', 'lw_gpf_exclude_product', 11, 3);
@negrocapo
Copy link

Hi! Does this code exclude some products from a category? And how should I do to completely exclude all the products from the category?

@leewillis77
Copy link
Author

Hi;

These snippets are part of the support for the Google Product Feed plugin. If you need assistance you'd need to open a ticket here: https://woocommerce.com/my-account/create-a-ticket/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment