Hi @sitharaek
Please follow these steps to find out what causing this error:
- If your website uses caching, it might cause delays in updating the displayed results. Try clearing it.
- Some themes or plugins might have their own settings for displaying products which could conflict with WooCommerce settings. Especially check if you don’t have a plugin that modifies the default stock levels of products in WooCommerce. Try disabling each plugin one by one or switching to the default WordPress theme to see if the issue persists.
- Disable “Hide out of stock items from the catalog” in WooCommerce -> Setting -> Products -> Inventory and use one from FiboSearch in WooCommerce -> FiboSearch -> Search config (tab). We respect the WooCommerce setting, but something along the way may overwrite this option.
- At last, you can try this snippet, which has the highest priority and will exclude out-of-stock products from the query.
function hide_out_of_stock_products( $query ) {
if ( ! is_admin() && ( is_archive() || is_search() ) && $query->is_main_query() ) {
$meta_query = $query->get( 'meta_query' );
$meta_query[] = array(
'key' => '_stock_status',
'value' => 'outofstock',
'compare' => 'NOT EXISTS',
);
$query->set( 'meta_query', $meta_query );
}
}
add_action( 'pre_get_posts', 'hide_out_of_stock_products', PHP_INT_MAX - 1 );
You have two ways to add this code to your theme:
- Open the
functions.php
in your child theme and add the code at the end.
- or install the Code Snippets plugin and apply this code as a snippet.
Regards,
Kris