• Resolved Jamie Gill

    (@patchgill)


    Hi There,

    OK I am trying to reorder countries following several examples online. I can run the following fine :-

    add_filter( 'woocommerce_countries',  'wc_custom_countries_order', 10, 1 );
    function wc_custom_countries_order( $countries ) {
      // replace with iso code of the country (example: US or GB)
      unset($countries['GG']);
      unset($countries['JE']);
      unset($countries['GB']);
      // replace with iso code of country AND country name (example: US | United States or GB | United Kingdom (UK)
      $countries = ['GB' => 'Mainland - United Kingdom'] + ['JE' => 'Jersey - United Kingdom'] + ['GG' => 'Guernsey - United Kingdom'] + $countries;
       
      return $countries;
    } 

    This works and on output and I kill the script it looks good. However if I let it load the order is still as was. I have tried adding the following :-

    add_filter('woocommerce_sort_countries', '__return_false');

    However this does not work either. It is like the initial code works for reordering but then something is happening after this to order by the order of countries set in the backend or something? I feel there must be something simple as everyone seems to have solutions that no longer works.

    Woo is up to date and this is a bespoke theme so nothing special is in place.

    Cheers
    J

Viewing 2 replies - 1 through 2 (of 2 total)
  • Margaret S. woo-hc

    (@margaretwporg)

    Hi @patchgill

    Thanks for sharing the code.

    Kindly note that reordering of countries can only be done programmatically, support for which is beyond the scope of this forum!

    * This particular forum is for questions that are directly related to the features and functionality of the free WooCommerce core plugin.

    This being a development topic, I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Lastly, for direct assistance with code customizations, I recommend consulting with the WooCommerce Customizations Partners. https://woocommerce.com/customizations/

    I hope this points you in the right direction.

    Thanks

    Margaret S. woo-hc

    (@margaretwporg)

    Seems we’ve not had additional inputs on this thread. Thus, we encourage you to make use of the above resources.

    I’ll go ahead and mark the thread as resolved but please feel free to create a new thread if you have further questions.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Reorder Countries’ is closed to new replies.