Skip to main contentSkip to footer

In some cases, WooCommerce product stock level changes don’t affect the search immediately. If the search is set up to exclude out-of-stock items, a product that sells out may still be included in the search until the next reindexing.

This happens because changes in the stock status don’t trigger a WordPress post update that Relevanssi listens to, and Relevanssi doesn’t know the post has changed. Thus the change in stock status goes unnoticed until something saves the post or rebuilds the index.

The fix for this is simple, fortunately. You can make Relevanssi listen to product stock status changes. Add these functions to your site:

add_action( 'woocommerce_product_set_stock_status', function( $product_id ) {
    relevanssi_insert_edit( $product_id );
} );

add_action( 'woocommerce_variation_set_stock_status', function( $product_id ) {
    relevanssi_insert_edit( $product_id );
} );

Now whenever a product stock status changes, Relevanssi is notified and reindexes the post. This will remove the post from the index if it goes out-of-stock and out-of-stock items are excluded.

This was originally asked on WP.org forums.

Your account

Not logged in. Log in to see your license details.

Search

Popular Resources

Proximity sorting
Relevanssi Premium 2.16 added proximity sorting to search results. That means you can sort the search results by geographic location.…
ACF: Indexing relationship content
If your posts include content from related posts using the Advanced Custom Fields relationship functionality, Relevanssi doesn’t index that content…

Related Posts:

Comment Section:

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed