Content of the page

Switch currency with language change


Content of the article

WPML:

  • open functions.php of your current wp theme
  • drop there next PHP code:
    add_filter('wp_head', function() {
        $lang = ICL_LANGUAGE_CODE;
        global $WOOCS;
        switch ($lang)
        {
            case 'bg':
                $WOOCS->set_currency('BGN');
                break;
            case 'en':
                $WOOCS->set_currency('EUR');
                break;
            default:
                $WOOCS->set_currency('USD');
                break;
        }
    });
  • See WPML docs about languages codes

Polylang:

  • open functions.php of your current wp theme
  • drop there next PHP code:
    add_filter('wp_head', function() {
        $lang = get_locale();
        global $WOOCS;
        switch ($lang)
        {
            case 'bg_BG':
                $WOOCS->set_currency('BGN');
                break;
            case 'en_GB':
                $WOOCS->set_currency('EUR');
                break;
            default:
                $WOOCS->set_currency('USD');
                break;
        }
    });
  • https://wordpress.org/support/topic/switch-currency-with-language-change-polylang/
  • See Polylang docs about languages codes

GTranslate:

  • open functions.php of your current wp theme
  • drop there next PHP code:
    add_filter('wp_head', function() {
        $lang = isset($_SERVER['HTTP_X_GT_LANG']) ? $_SERVER['HTTP_X_GT_LANG'] : '';
        global $WOOCS;
        switch ($lang)
        {
            case 'bg_BG':
                $WOOCS->set_currency('BGN');
                break;
            case 'en_GB':
                $WOOCS->set_currency('EUR');
                break;
            default:
                $WOOCS->set_currency('USD');
                break;
        }
    });
  • https://wordpress.org/plugins/gtranslate/

 

Faster WordPress Hosting