News:

Support the VirtueMart project and become a member

Main Menu

Default country by language

Started by Mike J, March 19, 2017, 23:29:34 PM

Previous topic - Next topic

Mike J

Does anyone know how to set by chosen language the default/preselected country in the cart?

For example
en-GB = United Kingdom
en-US = United States etc



VirtueMart 4.0.2 10661
Joomla! ‎3.10.11
PHP 7.4.30
mysql 5.7.39

GJC Web Design

GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

Mike J

Hello GJC Web Design,

No, I hadn't updated my profile on the forum since the last time I posted. So sorry about that (I find it incredible that he finds that incredible).

Yes.

Am currently using this : http://extensions.virtuemart.net/vm-orders/vm-localise-detail which does a pretty good job but would rather have the selected site language or currency determine the default/preselected country in my case (If it's not too much of a drama).

Anyways, that's for taking the time to respond... You're about the only one who ever does :)

M
VirtueMart 4.0.2 10661
Joomla! ‎3.10.11
PHP 7.4.30
mysql 5.7.39

MKI-Miro

why this is not included in virtuemart core?  :(

AH

MKI

I see another of your recent posts also mentions things being in the core.

Not everything is, or will be included, in the core.  That is why third party plugins exist.

When someone mentions a third party plugin then assume that your problem might be solveable, and you might have to assign some funds to your project to get things to work exactly how you want them.


Regards
A

Joomla 3.10.11
php 8.0

MKI-Miro

i am trying to do it on my own but country dropdown is not simple <select>

any idea how to code ?

MKI-Miro

#6
I have found that it uses chosen jquery plugin so solution is:

<?php
$lang = JFactory::getLanguage();
$langTag = $lang->getTag();
?>

<script>
  jQuery(document).ready(function(){

  <?php if ($langTag == "sk-SK") { ?>
      jQuery('#virtuemart_country_id_field').val(189);
      jQuery('#virtuemart_country_id_field').trigger("chosen:updated");
  <?php } elseif($langTag == "en-GB") { ?>
      jQuery('#virtuemart_country_id_field').val(222);
      jQuery('#virtuemart_country_id_field').trigger("chosen:updated");   
  <?php } elseif($langTag == "hu-HU") { ?>
      jQuery('#virtuemart_country_id_field').val(97);
      jQuery('#virtuemart_country_id_field').trigger("chosen:updated"); 
  <?php } elseif($langTag == "de-DE") { ?>
      jQuery('#virtuemart_country_id_field').val(81);
      jQuery('#virtuemart_country_id_field').trigger("chosen:updated"); 
  <?php } elseif($langTag == "de-AT") { ?>
      jQuery('#virtuemart_country_id_field').val(14);
      jQuery('#virtuemart_country_id_field').trigger("chosen:updated"); 
  <?php } elseif($langTag == "ro-RO") { ?>
      jQuery('#virtuemart_country_id_field').val(175);
      jQuery('#virtuemart_country_id_field').trigger("chosen:updated");   
  <?php } elseif($langTag == "pl-PL") { ?>
      jQuery('#virtuemart_country_id_field').val(170);
      jQuery('#virtuemart_country_id_field').trigger("chosen:updated");   
  <?php } ?>
  });
</script>

Studio 42

our code is not fine.
You should check if jQuery('#virtuemart_country_id_field').val() is empty or only call it if address (or check with js a required field) is empty on load.

And to simply your code or add other countries.
<?php 
$lang 
JFactory::getLanguage();
$langTag $lang->getTag();
$langId null;
if (
$langTag == "sk-SK"$langId 189;
elseif(
$langTag == "en-GB"$langId 222;
elseif(
$langTag == "hu-HU"$langId 97;
// add all $langTag ...
if($langId !==null) { ?>

<script>
  jQuery(document).ready(function(){
      jQuery('#virtuemart_country_id_field').val(<?php echo $langId ?>).trigger("chosen:updated");
  });
</script>
<?php