WPML

Overview of the Issue

When using YITH WooCommerce Ajax Search with WPML, you might experience the following issue: with WooCommerce Multilingual multi-currency the prices in the search results are the store currency amounts shown with the shopper’s currency symbol; a “load more” search right after the same search in another language can show that language’s products; the search form texts you save in the plugin’s settings are not in String Translation; and with the language as a parameter in the URL, “See all products” opens the results page in the default language with the products of every language.

Workaround

Go to WPMLSettingsCustom XML Configuration, add this code and save:

XML
<wpml-config><admin-texts><key name="yith_wcas_shortcodes_list"><key name="default"><key name="options"><key name="search-input"><key name="placeholder"/></key></key></key></key></admin-texts></wpml-config>
Then translate the placeholder in WPMLString Translation.
For the prices and the paged results, add this code to your theme’s functions.php file:
PHP
add_filter( 'ywcas_store_search_query', '__return_false' );
add_filter( 'ywcas_search_result_data', function ( $data ) {
  foreach ( (array) $data as $i => $r ) {
    $r = (array) $r;
    foreach ( [ 'min_price', 'max_price' ] as $k ) { if ( isset( $r[ $k ] ) ) { $r[ $k ] = (float) apply_filters( 'wcml_raw_price_amount', (float) $r[ $k ] ); } }
    $data[ $i ] = $r;
  }
  return $data;
}, 20 );
If your site uses the language as a parameter in the URL (WPMLSettingsLanguage URL format), create a file in wp-content/mu-plugins/ (for example wpml-ywcas-results-page.php) with this code. It must run before WPML sets the language, so it does not work from functions.php:
PHP
<?php
// 1. The block's results URL: remove WPML's ?lang= from the site URL.
add_filter( 'ywcas_block_common_localize', function ( $data ) {
    if ( isset( $data['siteURL'] ) ) {
        $data['siteURL'] = strtok( (string) $data['siteURL'], '?' );
    }
    return $data;
} );
// 2. The results page: WPML gets the language code, the plugin its locale.
if ( isset( $_GET['ywcas'], $_GET['lang'] ) && false !== strpos( (string) $_GET['lang'], '_' ) ) {
    global $wpdb;
    $wpml_ywcas_locale = sanitize_text_field( wp_unslash( $_GET['lang'] ) );
    $wpml_ywcas_code   = $wpdb->get_var( $wpdb->prepare( "SELECT code FROM {$wpdb->prefix}icl_languages WHERE default_locale = %s", $wpml_ywcas_locale ) );
    if ( $wpml_ywcas_code ) {
        $_GET['lang'] = $_REQUEST['lang'] = $wpml_ywcas_code;
        // WPML reads the language from the URL itself, not only from $_GET.
        foreach ( [ 'REQUEST_URI', 'QUERY_STRING' ] as $wpml_ywcas_key ) {
            if ( isset( $_SERVER[ $wpml_ywcas_key ] ) ) {
                $_SERVER[ $wpml_ywcas_key ] = str_replace( 'lang=' . rawurlencode( $wpml_ywcas_locale ), 'lang=' . $wpml_ywcas_code, (string) $_SERVER[ $wpml_ywcas_key ] );
            }
        }
        add_action( 'pre_get_posts', function () use ( $wpml_ywcas_locale ) {
            $_GET['lang'] = $_REQUEST['lang'] = $wpml_ywcas_locale;
        }, 9999998 );
    }
}

All known issues

Need Help with This Issue?

Ask a support question and we’ll look into it with you.