• Resolved gelion-pipi

    (@gelion42)


    Hello,

    I have an issue about the Country/Region field dropdown at checkout page.

    my default site language is Japanese. so the Japanese alphabetical order remains in the Country/Region field.

    I need to set it to A to Z order.

    How do I set it to A to Z order?

    Looking forward to hearing from you!

Viewing 7 replies - 1 through 7 (of 7 total)
  • You can use a custom function in your theme’s functions.php file.

    add_filter( 'woocommerce_sort_countries', 'custom_woocommerce_sort_countries' );

    function custom_woocommerce_sort_countries() {
    return 'asc'; // asc or desc
    }

    Thread Starter gelion-pipi

    (@gelion42)

    Hi

    Thank you for your response. I tried to add this code in my Snippet plugin. and the code didn’t work well. Do you have any other code that could be solved ?https://snipboard.io/x6qo8k.jpg

    Saif

    (@babylon1999)

    Hello @gelion42,

    The woocommerce_sort_countries hook takes only a boolean value.

    To sort the counties in descending order, please replace the existing snippet with the following:

    /* Change the sorting of the countries list on the checkout page   */
    
    add_filter( 'woocommerce_sort_countries', '__return_false' );
    add_filter( 'woocommerce_countries', 'custom_woocommerce_sort_countries' );
    
    function custom_woocommerce_sort_countries($countries) {
    	arsort($countries);
    return $countries;
    }

    To revert back to the default ascending order, simply change “arsort” to “asort”.

    Hope this helps! :?)

    Thread Starter gelion-pipi

    (@gelion42)

    Hello,

    Thank you for your help.

    Unfortunately, the code also didn’t work correctly.https://snipboard.io/qpL1ed.jpg

    The order of the country fields is still in Japanese alphabetical order.https://snipboard.io/IKN4qu.jpg. ??

    Saif

    (@babylon1999)

    The snippet works for both English and Japanese languages (please check screenshots below).

    Default order:


    Link to image: https://d.pr/i/RMa3A3

    With the snippet:


    Link to image: https://d.pr/i/T7bDBg


    However, if I understand correctly now, you’re not seeking to change the order of the countries, but rather to sort them as if the site were in English while maintaining the site’s language as Japanese, correct?

    This is quite challenging, as you need to convert the list to English, then apply the sorting. Please note that while we can provide guidance on minor code changes, developing custom solutions is beyond the scope of our support policy. If you need a developer to help you build a custom solution, consider hiring a WooExpert.

    Moreover, I’m curious about the method you’re using to translate the page shown in the screenshot. Are you relying on the Google Chrome translation feature?

    If that’s the case, then you can fix this with a translation plugin like TranslatePress. It will switch the language for the entire site. :?)

    Please check this screencast for context: https://d.pr/v/hCKkqj

    Cheers!

    Thread Starter gelion-pipi

    (@gelion42)

    Hello,

    Thank you for taking the time to give me advise.

    Currently, the default language on the site is Japanese.
    And I use a plug-in called Weglot to translate Japanese into English.

    However, when I switched to English on the site, for some reason, only the country field on the checkout page remained in Japanese. So we contacted weglot support, but they said “this is a JavaScript issue, so the best they can do for me is to send me this documentation. “

    https://www.w3schools.com/howto/howto_js_sort_list.asp

    But I don’t know much about JavaScript, so I ended up using Loco Translate to translate the names of countries that remained in Japanese into English. https://snipboard.io/jUSuVO.jpg

    Of course, because of this, the country name in the Japanese checkout field was also changed to English.
    And the order hasn’t changed.https://snipboard.io/KmHeEX.jpg

    I’d like to try TranslatePress, which you suggested, but I’m worried about interfering with Weglot and messing up the translation. Is it OK to use Weglot and TranslatePress at the same time?

    Looking forward to hearing from you!

    Hello @gelion42 ??

    Currently, the default language on the site is Japanese.
    And I use a plug-in called Weglot to translate Japanese into English.

    Thank you for reaching back, clarifying things further!

    I’d like to try TranslatePress, which you suggested, but I’m worried about interfering with Weglot and messing up the translation. Is it OK to use Weglot and TranslatePress at the same time?

    This is best to clarify with their respective support channel:

    https://translatepress.com/support/

    I trust that points you in the right direction, but if you have more questions, let us know.

    We’re happy to help.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Country field dropdown at checkout page’ is closed to new replies.