2015-01-02 200 views
0

谷歌搜索和搜索,但我找不到我在找什麼。根據貨幣在wordpress中更改貨幣位置

我在建立一個有2種貨幣的貨幣網站:KRW和USD。

我有兩個在這些貨幣之間切換的按鈕。

當選擇KRW時,價格顯示爲10,000W,當選擇USD時,顯示100 $。

我想要的是在選擇USD時顯示$ 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'); 

兩人都沒有工作。 :(

誰能幫助請,謝謝。

+0

網站如何知道是選擇KRW還是USD?你應該能夠過濾'get_option'並且定位'woocommerce_currency_pos'選項。 – helgatheviking

+0

我有一個貨幣切換器插件,它給了我一個切換貨幣的選項。 –

+0

在剛剛添加的代碼中,您有'woocommerce_price_format'過濾器傳遞的錯誤變量。 '$ format'和'$ currency_pos'可用。請參閱'wc-formatting-functions.php'。 我想問的是該插件如何知道顯示哪種貨幣? '$ _GET'變量?我不知道你使用了什麼插件,所以不知道它是如何工作的,因此只能猜測你應該如何過濾選項。 – helgatheviking

回答

0

這只是一個猜測,因爲我不知道是什麼插件,你正在使用或它是如何工作的。我會認爲它增加了一個$_GET變量命名currency到您的網址的結尾。www.example.com&currency=KRW但想法是,你設置了woocommerce_currency_pos選項的值基於貨幣插件提供了一些數據。

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'; 
    } 
} 

或者,我可以認爲「正確」是默認貨幣頭寸,並且您只需要過濾實例中的選項該網站以USD模式顯示。在這種情況下,您只需要以下內容

add_filter('pre_option_woocommerce_currency_pos', 'change_currency_position'); 
function change_currency_position(){ 
    if(isset($_GET['currency'] && 'USD' == $_GET['currency']){ 
     return 'left'; 
    } 
} 
+0

雖然它不適合我,但我明白了。感謝您的幫助! –

+0

當然,它不起作用,但我很高興你能夠得到正確的想法。 – helgatheviking