Viewing 5 replies - 1 through 5 (of 5 total)
  • Saif

    (@babylon1999)

    Thread Starter Taco Fleur

    (@metacofleurcom)

    About time they fix it then, this has caused me so much grief over the years, I had no idea where these people found some of these products that I hid.

    Plugin Support Moses M. (woo-hc)

    (@mosesmedh)

    Hi @metacofleurcom,

    I understand this issue is causing you trouble, and you’d like it resolved. While the case is still open, a temporary workaround is to add a filter that excludes products marked as hidden from search results.

    You can try the following code and let me know if it works for you:

    function exclude_hidden_products_from_search($query) {
        if (!is_admin() && $query->is_search() && $query->is_main_query()) {
            $query->set('post_type', 'product'); // Ensure only products are searched
    
            // Exclude hidden products using the WooCommerce taxonomy
            $query->set('tax_query', array(
                array(
                    'taxonomy' => 'product_visibility',
                    'field'    => 'slug',
                    'terms'    => 'exclude-from-search',
                    'operator' => 'NOT IN',
                ),
            ));
        }
    }
    add_action('pre_get_posts', 'exclude_hidden_products_from_search');
    

    Additionally, you may find this solution helpful:
    Stack Overflow: Remove WooCommerce Hidden Products from WordPress Default Search

    Thread Starter Taco Fleur

    (@metacofleurcom)

    Thank you, that’s great. It works but it messes up the layout of my site for some reason so I had to remove it. There were no errors in the log, so it’s really weird.

    I also cleared cache.

    • This reply was modified 6 days, 13 hours ago by Taco Fleur.
    Plugin Support shahzeen(woo-hc)

    (@shahzeenfarooq)

    Hi there!

    Thanks for the update! I understand that while the code filtered out hidden products, it caused an unexpected layout issue. Since customization is out of scope, my colleague made an exception and shared a code snippet, but unfortunately, it did not work as expected.

    In this case, I would suggest waiting until our developers address the issue. Alternatively, if you still need a solution, I can recommend?WooExperts?and?Codeable.io?as options for getting professional help. Alternatively, you can also ask your development questions in the??WooCommerce Community Slack?as custom code falls outside our usual?scope of support.

    As an alternative, you might consider using a search customization plugin that allows finer control over search results without modifying the query directly.

    Let me know if you’d like further guidance! ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.