• Resolved cyberws2015

    (@cyberws2015)


    Hi folks,

    I am hoping this is a really simple fix. When products on WooCommerce set with Catalogue Visibility to “hidden” they are still appearing in the Search.

    How can this what I would have thought should be “out of the box” functionality be achieved.

    Thanks in advance for any assistance.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    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.

    Thread Starter cyberws2015

    (@cyberws2015)

    Thanks a lot for this Michael, worked at treat.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Welcome.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Exclude products with Catalogue visibility “hidden” from search’ is closed to new replies.