• Resolved alrioart

    (@alrioart)


    If you go to my site Buy My Comics and Records and search for an item which is out of stock on the side search bar, it returns a listing for those out of stock items.
    When I click to the link to those out of stock items, I get a blank page.
    How can I stop showing out of stock items *not* available for back order.

    The page I need help with: [log in to see the link]

Viewing 14 replies - 1 through 14 (of 14 total)
  • Plugin Author ILLID

    (@mihail-barinov)

    Hello,

    So, as I understand, you want to hide out of stock items from the search results list.

    You can use pro plugin version that has special feature to display the products only with certain product staruses. Please read more here.

    Also – you can use following code snippet

    add_filter( 'aws_search_results_products', 'my_aws_search_results_products' );
    function my_aws_search_results_products( $products ) {
        if ( ! empty( $products ) ) {
            foreach( $products as $key => $product ) {
                $product = wc_get_product( $product['id'] );
                if ( is_a( $product, 'WC_Product' ) && ! $product->is_in_stock() ) {
                    unset( $products[$key] );
                }
            }
        }
        return $products;
    }

    You need to add it somewhere outside the plugins folder. For example, inside functions.php file of your theme or use some plugin for adding code snippets.

    Also after adding this code you will need to go to the plugin settings page and click the ‘Clear cache’ button.

    Thread Starter alrioart

    (@alrioart)

    There is a selection in the settings for “Show out-of-stock”
    Show out-of-stock products in search
    – I have it set to HIDE.
    Is that not what the selection is for? Is that not supposed to be in the Free version?

    Plugin Author ILLID

    (@mihail-barinov)

    Ops, yes you are right about that.

    So you set this option to ‘Hide’ but still see out of stock items inside your search results? Is so – please try to re-index plugin table and check search results one more time.

    Thread Starter alrioart

    (@alrioart)

    I cleared the cache and re-indexed and it still shows out of stock search results. Go to the site and Search “Gorillaz” or “Ricch” or “Osees” – just some out of stock items which appear in the quick preview as available. When I click the link in the search preview, it leads to a blank page.

    Plugin Author ILLID

    (@mihail-barinov)

    Ok, I just check for “Gorillaz” , “Ricch” and “Osees”.

    Here is what I see

    https://prnt.sc/whku15
    https://prnt.sc/whkubm
    https://prnt.sc/whkuh5

    So no any out of stock items inside the search results list. Or you see some other search results?

    Thread Starter alrioart

    (@alrioart)

    Yes, they are all out of stock. It has a links to all of these out of stock products.
    All of these out of stock products should not appear in the search results because they are out of stock.

    Plugin Author ILLID

    (@mihail-barinov)

    In those free examples I only see one product inside search results – for ?“Gorillaz” query and the product is in stock.

    All other search queries give some product categories inside the search results list. You want to hide these categories?

    Thread Starter alrioart

    (@alrioart)

    “Gorillaz” is not a category. It’s the name of a band. It’s the name of a Woocommerce Product. It’s out of stock and should not appear in the search results.
    Same for Ricch and Osees. They are out of stock. No mention of them at all should appear in the search results. Especially one that when you click it, leads to a blank page.

    Plugin Author ILLID

    (@mihail-barinov)

    So when searching for “Gorillaz” I see this – https://prnt.sc/wix38p

    Plugin show product tag ‘Gorillaz’ ( https://buymycomics.com/product-tag/gorillaz/ ) and product ‘Weezer – Weezer (Black Album) – Black and Clear Split, Colored Vinyl, 2019’ that is in stock. I don’t see any other products there.

    Maybe of mean that this tag ‘Gorillaz’ shoul not be displayed inside search results because page https://buymycomics.com/product-tag/gorillaz/ is empty?

    Regards

    Thread Starter alrioart

    (@alrioart)

    Yes, what you are seeing is correct. You are seeing Gorillaz in the search results when there are no Gorillaz in stock. When you click that link you get the empty results page.
    You have successfully identified the problem and it’s still an issue. Gorillaz should not appear in the search results if it’s not in stock.

    Weezer *is* in stock, so it showing is fine.

    Gorillaz is not in stock and should not show in search results.

    Thread Starter alrioart

    (@alrioart)

    FYI, Ricch is back in stock if you are still working on this. Gorillaz is still out of stock.
    If this isn’t something that can be fixed, please let me know.

    Plugin Author ILLID

    (@mihail-barinov)

    Well looks like I found the solution for you. It is a bit hacky but must work.
    Please use following code snippet

    add_filter( 'aws_terms_search_query', 'my_aws_terms_search_query' );
    function my_aws_terms_search_query( $sql ) {
        global $wpdb;
        $table_name = $wpdb->prefix . AWS_INDEX_TABLE_NAME;
        $sql = str_replace( 'FROM', 'FROM ' . $table_name . ',', $sql );
        $sql = str_replace( 'count > 0', "$wpdb->term_taxonomy.count > 0", $sql );
        $sql = str_replace( 'WHERE 1 = 1', "WHERE $wpdb->term_taxonomy.term_id = {$table_name}.term_id AND {$table_name}.in_stock = 1", $sql );
        return $sql;
    }

    You need to add it somewhere outside the plugins folder. For example, inside functions.php file of your theme or use some plugin for adding code snippets.

    Also after adding this code you will need to go to the plugin settings page and click the ‘Clear cache’ button.

    Thread Starter alrioart

    (@alrioart)

    Thank you! Out of stock products are no longer showing in the search results.

    Plugin Author ILLID

    (@mihail-barinov)

    Glad to help.

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Search showing out of stock items then blank results page’ is closed to new replies.