问题
Our WooCommerce site has 2 currencies. The primary currency is the Indian rupee and the secondary currency is USD (using currency switcher). I tried placing an order in USD but the YITH invoice shows the primary Indian rupee symbol in the invoice.
I have tried changing to all sorts of currency switcher plugins available but the symbol won't change in the invoice, it simply takes the default currency symbol.
I even tried adding 'get_woocommerce_currency_symbol()' to currency arg array to the YITH function. I Need help. The plugin used is 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:
The only way to get the order currency symbol (or code) is first getting the WC_Order
object and you can get it from the global $order;
object or from the $order_id
with:
$order = wc_get_order( $order_id );
Now you can use on it the WC_Abstract_Order
method get_currency()
to get the currency code and finally you will get the currency symbol this way:
$currency_code = $order->get_currency();
$currency_symbol = get_woocommerce_currency_symbol( $currency_code );
This is tested and works on WooCommerce 3+
来源:https://stackoverflow.com/questions/46606942/get-woocommerce-currency-symbol-from-order-in-yith-invoice-plugin