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

Polylang: Bilingual search
By default, Relevanssi indexes the different language versions of the posts separately. If your site is in French and English,…
Search shortcode

Relevanssi adds a shortcode to help making links to search results. That way users can easily find more information about a given subject from your blog. The syntax is simple: John Doe This will make the text John Doe a link to search results for John Doe. In case you…

bbPress: Private Groups support

Private Groups is a plugin that makes bbPress forum groups private. Relevanssi, however, doesn’t understand that privacy and will show those groups in the search results. Relevanssi has means to support this, however, with the help of the relevanssi_post_ok filter. Here’s some code from Mark Wass that makes the private…

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