• Skip to primary navigation
  • Skip to main content
OsomCode

OsomCode

Awesome code tutorials for WordPress and Genesis

  • Subscribe
  • My account
    • Edit profile
    • Favorites
    • Update credit card
  • Login

Hide out-of-stock WooCommerce products from search results

Learn in this tutorial how to hide out-of-stock WooCommerce products from search results using code.

By default, when the web visitor performs a search all WooCommerce products appear, but you may prefer to hide the ones that are currently out of stock.

Interested? Here’s how to do it.

Snippet to hide out-of-stock WooCommerce products from the results

Add the following code at the end of functions.php or in your functionality plugin:

To see this and another 847 code snippets of this website, login or subscribe here.

In this code you use the hook pre_get_posts in combination with conditional tags and the meta_key _stock_status.

Conclusion

As you can see, with a few lines of code you can hide search results for products without stock in WooCommerce.

Any questions? I read you in the comments.

And if you want to give me any suggestion for future tutorials, leave it in the contact form. Advantages of being a subscriber. 😉

PHP Products WooCommerce

To leave read and make questions about this code, you can login or register.

  • About OsomCode
  • FAQ
  • Contact

Legal Notice · Privacy Policy · Cookie Policy · Terms and conditions
Copyright © 2023

Lost your password?