> For the complete documentation index, see [llms.txt](https://knowledgebase.ajaxsearchpro.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://knowledgebase.ajaxsearchpro.com/miscellaneous/woocommerce/showing-products-in-stock-only.md).

# Showing products in-stock only

## Solution 1 (easy)

This solution is purely configuration based, highly recommended to use. Use solution 2 only if this is not working for some reason.\
&#x20;**Step 1:** Open up the *Frontend search settings -> Custom fields* panel

![](https://i.imgur.com/mxEAbj4.png)

**Step 2:** Make a *hidden* filter, on the *\_stock\_status* custom field, with the value of “instock”:

![](https://i.imgur.com/KlbovfN.png)

After saving the options, the filter should be working.

## Solution 2 (custom code)

I suggest using this solution if the first one is not working.

[What is this, and where do I put this custom code?](/safe-coding-guideline.md)

```php
add_filter( 'asp_pagepost_results', 'asp_stock_status_filter', 10, 1 );
function asp_stock_status_filter( $pageposts ) {
  foreach ($pageposts as $k=>$v) {
  
    // Get the stock status
    $stock_status = get_post_meta( $v->id, '_stock_status', true);
    if ( empty($stock_status) || $stock_status == "instock" ) 
      continue;
      
    unset($pageposts[$k]);    
  }
  return $pageposts;
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://knowledgebase.ajaxsearchpro.com/miscellaneous/woocommerce/showing-products-in-stock-only.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
