Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:

Cart items are not synced between languages with custom lang switcher.

Solution:

The user is tweaking our code example from WPML's documentation here.

https://wpml.org/documentation/getting-started-guide/language-setup/custom-language-switcher/#language-selector-with-flags-only

If your site is set to 'A different domain per language' Language URL format, then this code example will not sync the cart's content when you switch the language. But only by adding a class (wpml-ls-item) the element that holds the language's link, the issue is solved. This is the corrected code example.

function language_selector_flags(){
    $languages = icl_get_languages('skip_missing=0&orderby=code');
    if(!empty($languages)){
        foreach($languages as $l){
            if(!$l['active']) echo '<a class="wpml-ls-item" href="'.$l['url'].'">';
            echo '<img src="'.$l['country_flag_url'].'" height="12" alt="'.$l['language_code'].'" width="18" />';
            if(!$l['active']) echo '</a>';
        }
    }
}

Relevant Documentation:

https://wpml.org/documentation/getting-started-guide/language-setup/custom-language-switcher/

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

Our next available supporter will start replying to tickets in about 3.22 hours from now. Thank you for your understanding.

This topic contains 18 replies, has 2 voices.

Last updated by Itamar 4 years, 11 months ago.

Assisted by: Itamar.

Author Posts
December 19, 2019 at 11:11 am #5162625

FortunyShop

Thanks, I'm not interested in contractors, I'll just need your default code to work, then I'll customize it.
Thanks

December 22, 2019 at 10:52 am #5177979

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+02:00)

Hi.

Adding a class with the name "wpml-ls-item" to the

  • tag of your custom code solved the issue.
    function us_shop_link(){
        $languages = icl_get_languages('skip_missing=0&orderby=code');
        if(!empty($languages)){
            foreach($languages as $l){
                if(!$l['active']) {
                    if($l['language_code'] == "en_us") {
      
                        echo '
                            <li class="wpml-ls-item">
                              <a title="Go to the US Store" href="'.$l['url'].'">
                                <img src="<em><u>hidden link</u></em>" class="us-store-butt glow" alt="US store button" title="Go to the US Store">
                              </a>
                            </li>
                        ';
                   }
                }
            }
        }
    }
    

    I've checked it on your site and it is working.
    Can you please confirm this?

    Thanks,
    Itamar.

  • 2019-12-22_12-51-29.jpg
    December 23, 2019 at 8:47 am #5182861

    FortunyShop

    Thank you, the issue is solved!
    I confirm that now everything's working correctly!
    So I guess the "wpml-ls-item" is recalled in some javascript code that syncs the items in the cart.
    Thanks again!

    December 23, 2019 at 8:50 am #5182867

    Itamar
    Supporter

    Languages: English (English ) Hebrew (עברית )

    Timezone: Asia/Jerusalem (GMT+02:00)

    Great, I'm glad that it is solved now!

    I guess that you are right about the wpml-ls-item class.

    Good luck with your web projects 🙂
    Itamar.