Include “out of stock” products in search results

When Out of stock visibility is enabled in WooCommerce settings, the FiboSearch Out of stock visibility option automatically inherits this setting. However, if you need to hide products in the catalog but want to show them in the search results, you can override the setting with the following snippet:

// Force FiboSearch to show out of stock products in the autocomplete.
add_filter( 'dgwt/wcas/settings/load_value/key=exclude_out_of_stock', function ( $value ) {
    return 'off';
}, PHP_INT_MAX - 5 );

You have two ways to add this code to your theme:

  1. Open the functions.php file in your child theme and add the code at the end
  2. Or install the Code Snippets plugin and apply this code as a snippet.

The code above will show out of stock products only in the autocomplete. To show them also on the search results page, use the following code together with the previous snippet:

// Show out of stock products on the search results page,
// even if out of stock products are hidden from the catalog.
add_filter( 'pre_option_woocommerce_hide_out_of_stock_items', function ( $hide ) {
    if ( is_search() ) {
        $hide = 'no';
    }
    return $hide;
} );