Jump to content

Changing default country


Recommended Posts

In viewcart.tpl the selected country is taken from the installation defaullt, I want to set this to match the primary country for the language in use, I can set a value in the header, such as <country="FR"> but cant work out how to change the code below to use that to match to FR and  make France the default selected country.

                                    <form method="post" action="cart.php?a=setstateandcountry">
                                        <div class="form-group row">
                                            <label for="inputCountry" class="pt-sm-2 col-sm-4 control-label text-sm-right">{$LANG.orderForm.country}</label>
                                            <div class="col-sm-7">
                                                <select name="country" id="inputCountry" class="form-control">
                                                    {foreach $countries as $countrycode => $countrylabel}
                                                        <option value="{$countrycode}"{if (!$country && $countrycode == $defaultcountry) || $countrycode eq $country} selected{/if}>
                                                            {$countrylabel}
                                                        </option>
                                                    {/foreach}
                                                </select>
                                            </div>
                                        </div>

Link to comment
Share on other sites

12 hours ago, MrGettingRatherFrustrated said:

In viewcart.tpl the selected country is taken from the installation defaullt, I want to set this to match the primary country for the language in use, I can set a value in the header, such as <country="FR"> but cant work out how to change the code below to use that to match to FR and  make France the default selected country.

if it were a default template, and you wanted to define the variable in the template, you might get away with using the code below in viewcart.tpl...

{assign "country" $activeLocale.countryCode}

you could come unstuck with a few languages - Arabic (Argentina), and China (Taiwan) - but your site doesn't use either of those languages, so should be irrelevant... English might be an issue too (re US/UK/NZ/AUS etc - it will default to GB)

Edited by brian!
Link to comment
Share on other sites

And now the next question 🙂
I need to force a specific currency to be the default for a subsite, I have had a fiddle around but cant find a way to do this - basically I need to cause the equivalent of currency=9 to be the default for that subsite.

I am hoping that you have the answer somewhere in your deep vaults!

Link to comment
Share on other sites

19 hours ago, MrGettingRatherFrustrated said:

I need to force a specific currency to be the default for a subsite, I have had a fiddle around but cant find a way to do this - basically I need to cause the equivalent of currency=9 to be the default for that subsite.

well literally adding currency=9 to every link that goes to the subsite would be one option. 🙂

in practice, you'll have to check that the user wasn't logged in - because clients can't change their currency and can only see products priced in their own currency... so if these products weren't priced in that currency, they couldn't buy them.

setting the currency in the session would be another option - is this subsite outside of the cart (e.g sales pages), or is it a product group in the cart ?

Link to comment
Share on other sites

Thanks Brian,

There are a few factors behind this including usability and SEO so the horrible currency=n option wont achieve what I want 

Background:-
I have products that have country specific variants - ie different keyboard layouts, part numbers and even manufacturers warranty length, so I have two occurences of these products - one with only a GBP price and another with only a Euro price, so chosing the currency reveals different products.
As I have language specifc presentations of the site ie en_GB and fr_FR (and they only provide that single language which forces it to the default (lets ignore Belgium and Switzerland on that for now) etc - so I want to adjust the site to choose a country rather than language, remove the currency selector option and force the currency (there are other reasons for this such as not exposing me to EU import/export issues, exchange rate fluctuations and conversion costs).

I have found I can set the currency via session with a hook and I think that works for most pages - BUT found two issues.

1) Cookie Consent stops the hook running on page load - whether accepted or declined it then runs on a page refresh or change but that may be too late if there are no products initially displayed
2) As far as I can establish setting this via session wont work for search engines/indexing bots - ie my installations default is GBP so they will only see products in that

As an example https://www.truffiere.co.uk/en_GB/store/microsoft-surface-laptop-4 should show one set of products exclusively for the UK (and Ireland) as they are only priced in GBP

And https://www.truffiere.co.uk/fr_FR/store/microsoft-surface-laptop-4 should only show another set of products that are only priced in Euros

Currently flipping the currency between £ and € on those pages reveals different sets of products and the Euro products will never be found as the default returned for the group is in the installation currency

I'm open to ideas and suggestions

Edited by WHMCS ChrisD
Removed links to portal
Link to comment
Share on other sites

  • 3 weeks later...

I have this hook, with the assistance of WHMCS which changes the currency before page load, so that it achieves the desired result as stated above.

Hopefully it will be usefull for someone else

<?php

use WHMCS\Session;
// Provide your new default currency ID
$currencyId = 9;
if (!Session::get('uid') && !Session::get('currency')) {
Session::set('currency', $currencyId);
}
 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated