This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Reply To: WPML and Products are not displaying

Home Forums Product Support Forums Ajax Search Pro for WordPress Support WPML and Products are not displaying Reply To: WPML and Products are not displaying

#45883
Ernest MarcinkoErnest Marcinko
Keymaster

Thanks!

I think I have a solution for you. I have placed the following custom code to the functions.php file in the avada-child theme directory:

add_filter( 'asp_results', 'asp_change_lang_on_wpml', 10, 4 );
function asp_change_lang_on_wpml( $results, $search_id, $is_ajax, $args ) {
	global $sitepress;
	// Let us get the default site language if possible
	if ( is_object($sitepress) && method_exists($sitepress, 'get_default_language') ) {
		$site_lang_selected = $sitepress->get_default_language() == $args['_wpml_lang'];
	}
	$lang = $args['_wpml_lang'];
	var_dump($site_lang_selected);
	if ( !$site_lang_selected ) {
		foreach ($results as $k=>&$r) {
			if ( isset($r->post_type) && $r->post_type == $post_type ) {
				//$r->link = str_replace("/product/", "/product/".$lang."/", $r->link);
				$r->link = apply_filters('wpml_permalink', $r->link, $args['_wpml_lang'], true);
			}
		}
	}

    return $results;
}

So right now when I test on the english, I only get english or the ones that should show on both, with english URL. For the german, I turned off the compatibility (search ID=2) and now shows everything, and the URLS are corrected via the code.