Exclude Category from WooCommerce Related

Handy if you’re using the default category as “All Products” and want to prevent unrelated items from appearing related when no other categories are selected.

// exclude default category from related products
function exclude_default_from_related( $categories ){
    // array of category id's that should be excluded
    $exclude_cats = array( 15 );

	foreach( $categories as $index => $cat ){
		if( in_array( $cat, $exclude_cats ) ){
			unset( $categories[ $index ] );

	return $categories;
add_filter( 'woocommerce_get_related_product_cat_terms', 'exclude_default_from_related' );

Leave a Reply

katherine as a flat graphic icon

About Me

I’m an African / Ojibwe First Nations Web Developer living in Winnipeg, Manitoba.

Visit the Tips and Blog to see what I’m working on.