Something like this should suffice, as I’ve used it in some client work making use of Algolia:
function cyberws_algolia_exclude_visibly_hidden_products( $should_index, WP_Post $post ) {
if ( false === $should_index ) {
return false;
}
$product = wc_get_product( $post->ID );
if ( ! $product ) {
return $should_index;
}
$product_visibility = $product->get_catalog_visibility();
if ( 'hidden' === $product_visibility ) {
$should_index = false;
}
return $should_index;
}
add_filter( 'algolia_should_index_searchable_post', 'cyberws_algolia_exclude_visibly_hidden_products', 10, 2 );
add_filter( 'algolia_should_index_post', 'cyberws_algolia_exclude_visibly_hidden_products', 10, 2 );
Regarding why it’s not “done by default” is in part because not everyone is using Woocommerce with their websites. We definitely could add something like this to the plugin via the hooks shown above, we also try to not take on an assumptive approach of what people will or won’t want indexed. In this case, probably best to let in all the “searchable” content in and handle removing as needed/desired, than to assume something isn’t wanted in, and preventing from the getgo, leaving people potentially confused as to why it’s not there.