To get the default country ISO code and currency code in PrestaShop, you can use the following code snippet within your PrestaShop module or custom PHP script:
// Get the default country ID
$defaultCountryId = Configuration::get(‘PS_COUNTRY_DEFAULT’);
// Get the default country object
$defaultCountry = new Country($defaultCountryId);
// Get the ISO code of the default country
$defaultCountryIsoCode = $defaultCountry->iso_code;
// Get the default currency ID
$defaultCurrencyId = Configuration::get(‘PS_CURRENCY_DEFAULT’);
// Get the default currency object
$defaultCurrency = new Currency($defaultCurrencyId);
// Get the currency code of the default currency
$defaultCurrencyCode = $defaultCurrency->iso_code;
In the code above, we use the Configuration::get()
method to retrieve the IDs of the default country and currency set in the PrestaShop back office. Then, we create objects of the Country
and Currency
classes using the retrieved IDs. Finally, we can access the ISO code of the default country and the currency code of the default currency using the iso_code
property.
Please note that you should ensure that you have the necessary PrestaShop classes imported or autoloaded in your script/module for this code to work correctly.