• Resolved Olaf Lederer

    (@finalwebsites)


    Hi,

    I’m running a shop with WooCommerce and some of the products are set to get hidden from the search and the catalog.
    Together with your support I created this filter:

    
    function fws_exclude_hidden_products( $should_index, WP_Post $post ) {
        if ($product = wc_get_product( $post->ID )) {
            $visibility = $product->get_catalog_visibility();
            if ( $visibility == 'hidden' ) {
                $should_index = false;
            } 
        } 
        return $should_index;
    }
    add_filter( 'algolia_should_index_searchable_post', 'fws_exclude_hidden_products', 10, 2 );
    

    This code should exclude those products, but it doesn’t.
    Any idea what might be wrong?

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

    (@rayrutjes)

    Hi,

    Your code looks fine.

    A few remarks that might help:
    – You are currently only filtering out the hidden products from the searchable posts index. You might also be interested to remove it from the following hook: algolia_should_index_post.
    – Once you have added the code, you might need to manually delete the existing indices from the Algolia dashboard so that the hidden products get deleted.

    I hope that helps,

    Thread Starter Olaf Lederer

    (@finalwebsites)

    Hello Ray,

    thanks for the information. I added this filter
    add_filter( 'algolia_should_index_post', 'fws_exclude_hidden_products', 10, 2 );

    and removed two indexes and yes than it works!

    Plugin Contributor rayrutjes

    (@rayrutjes)

    That is great to hear!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to exclude hidden products?’ is closed to new replies.