> 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/how-to-search-products-by-variation-skus.md).

# How to search Products by variation SKUs?

For this to work, make sure you have configured and using the [index table engine](https://documentation.ajaxsearchpro.com/index-table) - as well as the [search in SKUs](/miscellaneous/woocommerce/how-to-search-products-and-product-sku.md) search is enabled.

By default, when the \_sku field is selected, the plugin will index the product SKUs as well as the variation SKUs - but all separately. To associate the **variation SKUs with the parent** product as well, use the code below.

**After adding the custom code**, make sure to re-create the search index.

![](/files/nT1KbiRckfgDKNAh05uR)

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

```php
add_filter( 'asp_post_custom_field_before_tokenize', 'asp_tokenize_sku_variation', 10, 3 );
function asp_tokenize_sku_variation($values, $post, $field) {
	if ( $post->post_type == 'product' && $field == '_sku' ) {
		$args = array(
			'post_type'     => 'product_variation',
			'post_status'   => array( 'private', 'publish' ),
			'posts_per_page'  => -1,
			'fields'          => 'ids',
			'post_parent'   => $post->ID // get parent post-ID
		);
		$variations = get_posts( $args );
		$skus = array();
		foreach ( $variations as $variation ) {
			$sku = get_post_meta($variation, '_sku', true);
			if ( !empty($sku) ) {
				$skus[] = $sku;
			}
		}
		if ( count($skus) > 0 ) {
			$values = array_merge($values, $skus);
		}
	}

	return $values;
}
```

**After adding the custom code**, make sure to re-create the search index.

![](/files/nT1KbiRckfgDKNAh05uR)


---

# 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:

```
GET https://knowledgebase.ajaxsearchpro.com/miscellaneous/woocommerce/how-to-search-products-by-variation-skus.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
