Created
October 5, 2020 13:16
-
-
Save leewillis77/efcea448952fbe468a3ea83dfd875f55 to your computer and use it in GitHub Desktop.
Exclude multiple categories from Google Product Feed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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