WPCS - WordPress Currency Switcher

Switch currency with language change

WPML:

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

Polylang and TranslatePress:

  • open functions.php of your current wp theme
  • drop there next PHP code:
    add_filter('wp_head', function() {
        $lang = get_locale();
        global $WPCS;
        switch ($lang)
        {
            case 'bg_BG':
                $WPCS->storage->set_val('wpcs_current_currency', 'BGN');
                break;
            case 'en_GB':
                $WPCS->storage->set_val('wpcs_current_currency', 'EUR');
                break;
            default:
                $WPCS->storage->set_val('wpcs_current_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 $WPCS;
        switch ($lang)
        {
            case 'bg_BG':
                $WPCS->storage->set_val('wpcs_current_currency', 'BGN');
                break;
            case 'en_GB':
                $WPCS->storage->set_val('wpcs_current_currency', 'EUR');
                break;
            default:
                $WPCS->storage->set_val('wpcs_current_currency', 'USD');
                break;
        }
    });
  • https://wordpress.org/plugins/gtranslate/