Reply To: WPML translation and search

#8832

frankdm
Participant

Disabling WPML compatibilty makes the search on the localized version work (sounds like it works backwards but it works)…

HOWEVER, when clicking a search result on the localized version it adds a product to the cart in the site default language.. (in essence the language switches to default when clicking) so I guess there will have to be some sort of “condition” that it checks what the current language is and uses that “add to cart” string instead of the default one ? Currently when a search result is clicked, this is what happens:

add_filter( 'asp_results', 'asp_links_to_addtocart', 1, 1 );

function asp_links_to_addtocart( $results ) {
foreach ($results as $k=>$r) {
// Modify the URL
$results[$k]->link = “/?add-to-cart=”.$r->id.”&quantity=1″;
}
return $results;
}

As this code happens on the result click both in the default language as any translated pages it turns the site back to the default language when you click a result….

In there it will need some form of detection and alteration of the “add to cart” url based on the current localization? That is how I see this..

  • This reply was modified 2 years, 2 months ago by  frankdm.