Stand with Ukraine. Fight for freedom and democracy

Donate
Troubleshooting //
Including/Excluding Out-of-Stock products in Search

Including/Excluding Out-of-Stock products in Search

Question

How can I configure the search on my page to include/exclude some products from the search results, for example, products out of stock?

Answer

If you wish to exclude some products and not show them in the search results, configure your WordPress search results with the AJAX Search widget or Block according to the steps below.

Tutorial requirements:

  • Elementor free version or Block Editor;
  • JetSearch plugin installed and activated;
  • content to search;
  • JetStyleManager for Gutenberg for styling (optional).

Table of Contents: 

The search will be performed based on the WooCommerce product’s field Stock, which takes two possible values: In Stock and Out-of-Stock.

custom product posts to include or exclude from search

Include/Exclude Out-of-Stock Products in Search in Elementor

Place the Ajax Search widget

Open a page you want to apply the Ajax Search widget. Place this widget on the page.

elementor page with ajax search widget

Select the source for the search

Navigate to the Search Query settings of the Ajax Search widget. 

Unscroll the Search Query section and specify the source of the search. To do this, proceed to the Search drop-down menu and choose the type of content (i.e., posts, pages, CPT, etc.).

selecting the source for search in elementor

This configuration allows searching for all products without excluding some of them.

Exclude the specific products

To exclude products Out-of-Stock from the search results, navigate to the Exclude tab. Type some symbols of the necessary Terms to find them and choose from the drop-down menu: “Product visibility: outofstock”.

search query section settings for search

This setting limits the search area; therefore, the search results do not have other products. 

Read about How to Exclude Certain Terms and Posts in AJAX Search Query in Elementor and Gutenberg.

Include/Exclude Out-of-Stock Products in Search in Gutenberg

Place the Ajax Search block

Open a page you want to apply the Ajax Search block and place this block on the page.

gutenberg page with ajax search block

Select the source for the search

To specify the search area of the website’s content, navigate to the Search Query section of this block and select the source of the search (i.e., Products). Choose the taxonomy you need from the drop-down menu.

selecting the source for search in gutenberg

The search results show all products without excluding them.

search results without excluding in gutenberg

Exclude specific products

To exclude some content from the search results, navigate to the Ajax Search block’s Search Query Includes/Excludes section and choose the appropriate settings from the drop-down menus.

search query include and exclude section

It allows us to show only the information referring to these settings and exclude the products out of stock.

search results with excluded products

Managing these settings allows including or excluding specific products from the search results.

Was this article helpful?
YesNo
Still need help?
Submit a request