Skip to content

Instantly share code, notes, and snippets.

@tw2113
Created Feb 18, 2022
Embed
What would you like to do?
<?php
function wds_algolia_exclude_catalog_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', 'wds_algolia_exclude_catalog_hidden_products', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment