2017-10-06 73 views
1

我們WooCommerce站點有2種貨幣。主貨幣是印度盧比和次要貨幣是USD(使用貨幣切換器)。我試圖訂貨在USD但YITH發票示出了在發票主印度盧比符號。獲取Woocommerce貨幣符號從YITH發票以便插件

我試圖改變現有的各種貨幣切換器的插件,但符號發票不會改變,它只是簡單地採用默認的貨幣符號。

我甚至嘗試添加「get_woocommerce_currency_symbol()」到貨幣ARG陣列到YITH功能。我需要幫助。使用的插件是YITH Invoice ver:1.3.11。

function yith_get_formatted_price ($price, $args = array()) { 
    extract (apply_filters ('wc_price_args', wp_parse_args ($args, array (
     'ex_tax_label'  => false, 
     'currency'   => get_woocommerce_currency_symbol(), 
     'decimal_separator' => wc_get_price_decimal_separator(), 
     'thousand_separator' => wc_get_price_thousand_separator(), 
     'decimals'   => wc_get_price_decimals(), 
     'price_format'  => get_woocommerce_price_format(), 
    )))); 

    $negative = $price < 0; 
    $price = apply_filters ('raw_woocommerce_price', floatval ($negative ? $price * - 1 : $price)); 
    $price = apply_filters ('formatted_woocommerce_price', number_format ($price, $decimals, $decimal_separator, $thousand_separator), $price, $decimals, $decimal_separator, $thousand_separator); 

    if (apply_filters ('woocommerce_price_trim_zeros', false) && $decimals > 0) { 
     $price = wc_trim_zeros ($price); 
    } 

    $formatted_price = ($negative ? '-' : '') . sprintf ($price_format, get_woocommerce_currency_symbol ($currency), $price); 
    $return   = $formatted_price; 

    return apply_filters ('wc_price', $return, $price, $args); 
} 

回答

1

獲取訂單貨幣符號(或者代碼),唯一的辦法就是先得到WC_Order對象,並可以從global $order;對象或從$order_id用得到它:

$order = wc_get_order($order_id); 

現在你可以使用WC_Abstract_Order方法get_currency()到g等貨幣代碼,最終你會得到貨幣符號是這樣的:

$currency_code = $order->get_currency(); 
$currency_symbol = get_woocommerce_currency_symbol($currency_code); 

這是測試和工程上WooCommerce 3+

+1

是的,這工作完美。由於$ current_order = $ document-> order;已在發票功能頁面中定義。然後我必須添加一個方法// global $ woocommerce; $ order_currency = $ current_order-> get_order_currency();其次是地方wc_price來獲得價格陣列(「貨幣」 => $ order_currency)。 – SandeepTete