WPML translation and search

Home Forums Product Support Forums Ajax Search Pro for WordPress Support WPML translation and search

This topic contains 10 replies, has 2 voices, and was last updated by frankdm frankdm 7 years, 6 months ago.

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #8819
    frankdm
    frankdm
    Participant

    Hey

    I am trying to setup WPML to translate my woocommerce store. I am running into an issue with the search plugin. It is not showing any results in the localized version. Works fine in the default site language.

    As search is pretty vital for my site (with a few thousand products), I need it to work in either language!

    I am not using single product pages at all. My search is setup to add straight to cart when clicking a result. Not sure if it matters really but it means it does not have to try and link to a translated single product page.. it can still just add to cart just as it is working for my default language.

    Thanks!

    #8822
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi!

    If you mean that it does not show any results when you switch to the localized language of the site and then do a search, then I can only think of one possible cause: On the Compatibility Options submenu the Use the custom ajax handler? option is turned off: https://i.imgur.com/KGUK9mU.png

    If you however mean returning results on the main site from the localized site as well, then you will have to turn off the WPML compatibility option on the Advanced options -> Content panel on the search settings page: https://i.imgur.com/psTtRX5.png

    Let me know if this helps.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #8832
    frankdm
    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 7 years, 6 months ago by frankdm frankdm.
    #8841
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi!

    Your code looks correct to me.

    As far as I know WPML does create separate posts with different IDs for translations, so the post ID should be enough as the argument for the cart to know which language to use. The icl_translations table only hods the relationship information of the translated posts.

    I think (I’m not sure) this might be an issue with how the cart handles the URL. I’m guessing it automatically gets the actual site translations, no matter if the post ID represents a different locale.

    I’m not sure if it’s possible to force it somehow to display items in original locales, as WPML kicks in and it automatically converts everything to the current language. It might be converted automatically when it’s displayed, not when added to cart.

    After digging a bit, I have found this and this. Based on those, I’ve made a modification to your filter:

    But I highly doubt it will make any difference if the item language is converted upon displaying. In that case I’m not sure if there is anything we can change within the search code. Let me know if you find anything!

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #8845
    frankdm
    frankdm
    Participant

    Hey, this code totally crashes my site with the following error:
    Parse error: syntax error, unexpected ‘$lang_arg’ (T_VARIABLE) in /home/mysite/public_html/wp-content/themes/StyleShop/functions.php on line 960

    Had to go into the ftp to change the functions.php back to the original to get it back. It might work based on what I see but somewhere there is a parsing error.

    This is the difference to the add to cart url:

    The default language uses this:
    http://mysite.com/?page_id=6800&add-to-cart=4289

    The translated language uses this:
    http://mysite.com/?page_id=6800&lang=nl&add-to-cart=4289

    So if the search would use that translated style add to cart url when on the default language it would work (I only got two languages)

    I mean, pressing other “add to cart” buttons on the translated pages work fine, it redirects to the localized version of the cart page. However I think the code in functions.php as it is does not get automatically adjusted. So again, I think your code has potential, maybe it has a small error somewhere that crashes it at the moment. But the idea of checking what language we are in and then changing the url should work fine… all that needs to happen is for it to add the “&lang=nl” part to the url when we are on the translated pages and not add it on the site default language.

    #8847
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    That is exactly what I was aiming for regarding the URL. I found the mistake, there was a missing “)” closing character on line 7.

    This should be error free now:

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #8848
    frankdm
    frankdm
    Participant

    Hey,

    This code does not crash the page no more, however, now the search is never ending. I mean, it keeps “searching”, the “load icon” keeps spinning and never shows any results. So in essence it “hangs” on something.

    Do you want access to my site so you can see the problem first hand? That might e easier to troubleshoot.

    #8850
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    It might indicate an error sourcing from the code still.

    The only thing I can think of in this case is that maybe the “wpml_get_language_information” function is not available at the time of execution, the other lines should not throw any error messages.

    Make sure that you don’t have the custom ajax handler option activated on the Compatibility Settings plugin submenu: https://i.imgur.com/g5WZ23V.png

    If that’s not it, then I will have to see it in order to be able to tell what might be causing the problem. In that case if you can provide temporary admin and FTP details to your test environment, it would help me a lot.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #8851
    frankdm
    frankdm
    Participant
    You cannot access this content.
    #8852
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Thank you for the details. I think I have found a different solution.

    Currently I’ve added the following code to your functions.php file:

    This basically get’s the language argument that is passed to the search, and adds it to the end of the result URLs. Let me know if this works 🙂

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #8853
    frankdm
    frankdm
    Participant

    This seem to work perfectly! Should anything “break” for some reason I will let you know but looks good.

    Thanks!

Viewing 11 posts - 1 through 11 (of 11 total)

The topic ‘WPML translation and search’ is closed to new replies.