• Resolved sitharaek

    (@sitharaek)


    Hi,

    Hide out of stock items option is enabled in my woocommerce settings, still some out of stock products are showing in the search result. Please help with this issue.

Viewing 1 replies (of 1 total)
  • Plugin Support Kris

    (@c0nst)

    Hi @sitharaek

    Please follow these steps to find out what causing this error:

    1. If your website uses caching, it might cause delays in updating the displayed results. Try clearing it.
    2.  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.
    3. 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.
    4.  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:

    1. Open the functions.php 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.

    Regards,
    Kris

Viewing 1 replies (of 1 total)
  • The topic ‘Out of stock products are showing in search result’ is closed to new replies.