wordpress woocommerce get_woocommerce_currency_symbol()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18365551/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
woocommerce get_woocommerce_currency_symbol()
提问by danyo
I am developing an extension for woocommerce WordPress plugin.
我正在开发 woocommerce WordPress 插件的扩展。
I would like to display the currency symbol outside of the loop in a custom function
我想在自定义函数中在循环之外显示货币符号
I have the following:
我有以下几点:
function my_function( ) {
global $woocommerce;
echo get_woocommerce_currency_symbol();
}
I am not sure why but this doesn't output the symbol? Am I missing something?
我不知道为什么,但这不输出符号?我错过了什么吗?
回答by jnhghy - Alexandru Jantea
Your code should work, which means the issue might be in the database. You can check this 2 functions:
get_woocommerce_currency()and get_woocommerce_currency_symbol()
from the woocommerce docs that shows that you are using the functions correct.
What is left is for you to start some troubleshooting steps to see what causes the error:
what is get_option('woocommerce_currency')
returnning? if nothing then you have no currency set and that is why you get nothing from get_woocommerce_currency_symbol();
What happens if you add a currency as a parameter to get_woocommerce_currency_symbol
? it gets displayed? something like echo get_woocommerce_currency_symbol("USD");
You should add to your script some error handling lines, to inform the user that he needs to have the currency set before using your extension.
您的代码应该可以工作,这意味着问题可能出在数据库中。您可以从 woocommerce 文档中检查这两个函数:
get_woocommerce_currency()和get_woocommerce_currency_symbol()
,表明您正在正确使用这些函数。
剩下的就是让您开始一些故障排除步骤以查看导致错误的原因:返回的
是get_option('woocommerce_currency')
什么?如果什么都没有,那么你就没有设置货币,这就是为什么你没有得到任何get_woocommerce_currency_symbol();
东西如果你添加一个货币作为参数会发生get_woocommerce_currency_symbol
什么?它被显示?像echo get_woocommerce_currency_symbol("USD");
你应该添加到您的脚本中一些错误处理线,以告知他需要有使用你的分机号之前的货币组中的用户。
回答by MakeWebBetter
You should always price under wc_price function, it will automatically add currency symbol along with the default span of woo commerce
您应该始终在 wc_price 函数下定价,它会自动添加货币符号以及 woo commerce 的默认跨度
For ex..
$product_price = 60;
echo wc_price($product_price);
回答by Hritik Pandey
use this to show price with currency
用它来显示货币价格
$product->get_price_html();
OR use
或使用
echo get_woocommerce_currency_symbol();
to show the currency only
只显示货币
回答by Mukii kumar
get_option('woocommerce_currency')
will help you lot.
会帮助你很多。
回答by KTrivedi
function get_woocommerce_currency_symbol( $currency = '' ) {
if ( ! $currency ) {
$currency = get_woocommerce_currency();
}
$symbols = apply_filters( 'woocommerce_currency_symbols', array(
'AED' => '?.?',
'AFN' => '?',
'ALL' => 'L',
'AMD' => 'AMD',
'ANG' => '?',
'AOA' => 'Kz',
'ARS' => '$',
'AUD' => '$',
'AWG' => '?',
'AZN' => 'AZN',
'BAM' => 'KM',
'BBD' => '$',
'BDT' => '? ',
'BGN' => 'лв.',
'BHD' => '.?.?',
'BIF' => 'Fr',
'BMD' => '$',
'BND' => '$',
'BOB' => 'Bs.',
'BRL' => 'R$',
'BSD' => '$',
'BTC' => '?',
'BTN' => 'Nu.',
'BWP' => 'P',
'BYR' => 'Br',
'BZD' => '$',
'CAD' => '$',
'CDF' => 'Fr',
'CHF' => 'CHF',
'CLP' => '$',
'CNY' => '¥',
'COP' => '$',
'CRC' => '?',
'CUC' => '$',
'CUP' => '$',
'CVE' => '$',
'CZK' => 'K?',
'DJF' => 'Fr',
'DKK' => 'DKK',
'DOP' => 'RD$',
'DZD' => '?.?',
'EGP' => 'EGP',
'ERN' => 'Nfk',
'ETB' => 'Br',
'EUR' => '',
'FJD' => '$',
'FKP' => '£',
'GBP' => '£',
'GEL' => '?',
'GGP' => '£',
'GHS' => '?',
'GIP' => '£',
'GMD' => 'D',
'GNF' => 'Fr',
'GTQ' => 'Q',
'GYD' => '$',
'HKD' => '$',
'HNL' => 'L',
'HRK' => 'Kn',
'HTG' => 'G',
'HUF' => 'Ft',
'IDR' => 'Rp',
'ILS' => '?',
'IMP' => '£',
'INR' => '?',
'IQD' => '?.?',
'IRR' => '?',
'IRT' => '?????',
'ISK' => 'kr.',
'JEP' => '£',
'JMD' => '$',
'JOD' => '?.?',
'JPY' => '¥',
'KES' => 'KSh',
'KGS' => 'сом',
'KHR' => '?',
'KMF' => 'Fr',
'KPW' => '?',
'KRW' => '?',
'KWD' => '?.?',
'KYD' => '$',
'KZT' => 'KZT',
'LAK' => '?',
'LBP' => '?.?',
'LKR' => '??',
'LRD' => '$',
'LSL' => 'L',
'LYD' => '?.?',
'MAD' => '?.?.',
'MDL' => 'MDL',
'MGA' => 'Ar',
'MKD' => 'ден',
'MMK' => 'Ks',
'MNT' => '?',
'MOP' => 'P',
'MRO' => 'UM',
'MUR' => '?',
'MVR' => '.?',
'MWK' => 'MK',
'MXN' => '$',
'MYR' => 'RM',
'MZN' => 'MT',
'NAD' => '$',
'NGN' => '?',
'NIO' => 'C$',
'NOK' => 'kr',
'NPR' => '?',
'NZD' => '$',
'OMR' => '?.?.',
'PAB' => 'B/.',
'PEN' => 'S/.',
'PGK' => 'K',
'PHP' => '?',
'PKR' => '?',
'PLN' => 'z?',
'PRB' => 'р.',
'PYG' => '?',
'QAR' => '?.?',
'RMB' => '¥',
'RON' => 'lei',
'RSD' => 'дин.',
'RUB' => '?',
'RWF' => 'Fr',
'SAR' => '?.?',
'SBD' => '$',
'SCR' => '?',
'SDG' => '?.?.',
'SEK' => 'kr',
'SGD' => '$',
'SHP' => '£',
'SLL' => 'Le',
'SOS' => 'Sh',
'SRD' => '$',
'SSP' => '£',
'STD' => 'Db',
'SYP' => '?.?',
'SZL' => 'L',
'THB' => '?',
'TJS' => '?М',
'TMT' => 'm',
'TND' => '?.?',
'TOP' => 'T$',
'TRY' => '?',
'TTD' => '$',
'TWD' => 'NT$',
'TZS' => 'Sh',
'UAH' => '?',
'UGX' => 'UGX',
'USD' => '$',
'UYU' => '$',
'UZS' => 'UZS',
'VEF' => 'Bs F',
'VND' => '?',
'VUV' => 'Vt',
'WST' => 'T',
'XAF' => 'Fr',
'XCD' => '$',
'XOF' => 'Fr',
'XPF' => 'Fr',
'YER' => '?',
'ZAR' => 'R',
'ZMW' => 'ZK',
) );
$currency_symbol = isset( $symbols[ $currency ] ) ? $symbols[ $currency ] : '';
return apply_filters( 'woocommerce_currency_symbol', $currency_symbol, $currency );
}
[1]: http://woocommerce.wp-a2z.org/oik_api/get_woocommerce_currency_symbol/
回答by Tehseen Ahmed
You want to show the WooCommerce curency symbol in your Custom WordPress Theme or Plugin but don't know how? Worry no more. Here is all you need to know. For Custom WooCommerce WordPress Plugin:
您想在自定义 WordPress 主题或插件中显示 WooCommerce 货币符号,但不知道如何显示?不用担心了。这是您需要知道的一切。对于自定义 WooCommerce WordPress 插件:
function show_currency_symbol( ) {
global $woocommerce;
echo get_woocommerce_currency_symbol();
}
For Custom WooCommerce WordPress Theme:
对于自定义 WooCommerce WordPress 主题:
<?php global $woocommerce; echo get_woocommerce_currency_symbol(); ?>
回答by Vijendra Yadav
This short code uses the woocommerce_price
function; it will automatically add currency symbol along with the default span of woo commerce.
这段简短的代码使用了woocommerce_price
函数;它将自动添加货币符号以及 woo commerce 的默认跨度。
/* Custom price */
$price = 100;
echo woocommerce_price($price);
/* Custom price */
$price = 100;
echo woocommerce_price($price);