在wordpress中根据货币更改货币位置

时间:2015-01-02 02:48:43

标签: switch-statement woocommerce currency

用Google搜索并搜索但我无法找到我要找的东西。

我正在建立一个拥有2种货币的woocommerce网站:KRW和USD。

我有两个按钮可以在这些货币之间切换。

选择KRW时,价格显示10,000W,选择USD时,显示100 $。

我想要的是在选择美元时显示100美元。

我尝试了我的functions.php:

add_filter('woocommerce_price_format','change_currency_pos');

function change_currency_pos( $currency_pos, $currency ) {
     switch( $currency ) {
          case 'USD': $currency_pos = '%1$s%2$s'; break;
          case 'KRW': $currency_pos = '%2$s%1$s'; break;
     }
     return $currency_pos;
}

也尝试过:

    function change_currency_pos() {
        $currency_pos = get_option('woocommerece_currency');

        switch($currency_pos) {
            case 'USD': $format = '%1$s%2$s'; break;
            case 'KRW': $format = '%2$s%1$s'; break;
        }
        return $currency_pos;
        }

   add_filter('woocommerce_price_format','change_currency_pos');

两者都不起作用。 :(

请有人帮忙吗。谢谢。

2 个答案:

答案 0 :(得分:1)

这只是一个猜测因为我不知道你正在使用什么插件或它是如何工作的。我将假设它在您的URL末尾添加了一个名为$_GET的{​​{1}}变量。 currency但您的想法是根据货币插件提供的某些数据为www.example.com&currency=KRW选项设置值。

woocommerce_currency_pos

或者,我可以假设"对"是默认货币位置。并且您只需要在以USD模式显示站点的实例中过滤选项。在这种情况下,您只需要以下

add_filter( 'pre_option_woocommerce_currency_pos', 'change_currency_position' );
function change_currency_position(){
    if( ! isset( $_GET['currency'] ) {
        return false;
    }

    if ( 'USD' == $_GET['currency'] ){
        return 'left';
    } elseif ( 'KRW' == $_GET['currency'] ){
        return 'right';
    } 
}

答案 1 :(得分:0)

要使 woocommerce_price_format 正常工作,您需要像这样设置格式

@bot.command()
async def hangman(ctx):
    """Play hangman!"""
    game = Hangman(ctx, self.bot)
    await game.play()
相关问题