Last active
October 8, 2016 19:05
-
-
Save timersys/9eb4e25d338f45169846aeb3afa9a05f to your computer and use it in GitHub Desktop.
Change default currency on woocommerce depending on user country
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Change default WPML Woocommerce currency | |
* depending on user's country | |
* https://timersys.com/?p=21090&preview=true | |
*/ | |
function geot_woo_default_currency( $currency ) { | |
if( ! function_exists( 'geot_country_code' ) || isset( $_COOKIE['geot_currency'] ) ) | |
return $currency; | |
$user_country = geot_country_code(); | |
switch( $user_country ) { | |
case 'CH': | |
$currency = 'CHF'; | |
break; | |
case 'US': | |
$currency = 'USD'; | |
break; | |
default: | |
$currency = 'EUR'; | |
break; | |
} | |
// save cookie to execute this only once | |
setcookie( 'geot_currency', $currency, time() + (86400 * 30), "/"); | |
return $currency; | |
} | |
add_filter('wcml_client_currency','geot_woo_default_currency'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment