> For the complete documentation index, see [llms.txt](https://developers.weglot.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers.weglot.com/cms/wordpress/use-cases/advanced-woo-search-x-weglot.md).

# Advanced Woo Search X Weglot

Advanced Woo Search (aws) is a plugin to make advance search with WooCommerce. You can find the plugin here : https\://wordpress.org/plugins/advanced-woo-search/

To make Advanced Woo Search return results in translated languages, reverse-translate the search terms into your original language before the search runs. The right hook (see the [Advanced Woo Search hooks reference](https://advanced-woo-search.com/guide/hooks-reference/)) is `aws_search_terms`.

```php
use WeglotWP\Helpers\Helper_API;

add_filter( 'aws_search_terms', 'my_aws_search_terms' );
function my_aws_search_terms( $terms ) {
    $original_language = weglot_get_original_language();
    $current_language  = weglot_get_current_language();
    if ( $original_language === $current_language || ! $terms ) {
        return $terms;
    }

    $option_services = weglot_get_service( 'Option_Service_Weglot' );
    $api_key_private = $option_services->get_api_key_private();

    foreach ( $terms as $key => $term ) {
        $request_body = wp_json_encode( array(
            'l_from'      => $current_language,
            'l_to'        => $original_language,
            'request_url' => home_url( '/' ),
            'words'       => array(
                array( 'w' => $term, 't' => 1 ),
            ),
        ) );

        $url      = sprintf( '%s/translate?api_key=%s', Helper_API::get_api_url(), $api_key_private );
        $response = wp_remote_post( $url, array(
            'body'        => $request_body,
            'headers'     => array( 'Content-Type' => 'application/json' ),
            'method'      => 'POST',
            'data_format' => 'body',
        ) );

        if ( is_wp_error( $response ) ) {
            continue; // Keep the original term if the request fails.
        }

        $response_data = json_decode( wp_remote_retrieve_body( $response ), true );
        if ( isset( $response_data['to_words'][0] ) ) {
            $terms[ $key ] = $response_data['to_words'][0];
        }
    }

    return $terms;
}
```


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://developers.weglot.com/cms/wordpress/use-cases/advanced-woo-search-x-weglot.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
