我需要将管理区域(post编辑)中的自定义字段格式化为货币eq: 12.000,00,用户只键入数字、和。自动的。我四处寻找,没有成功..。有没有人?谢谢
我试图在admin中对脚本进行队列排列的代码是
function enqueue_admin() {
wp_enqueue_script( 'jquery' ); //adding Jquery to admin. Not sure if is needed or already there
wp_register_script( 'autonum', THEME_DIR . '/js/vendor/autoNumeric.js', array( 'jquery' ), '1', false ); //this is autoNumeric for currency format
wp_enqueue_script( 'autonum' );
}
add_action( 'admin_enqueue_scripts', 'enqueue_admin' );此外,由于wordpress的兼容性,我也不确定是否需要将autoNumeric.js中的所有$更改为autoNumeric.js
发布于 2020-06-01 07:35:58
您还可以使用WordPress函数数_格式化_i18n,它使用用户区域设置来格式化值。
echo number_format_i18n($number, 2)另外,不要使用PHP函数,因为它在钱币_格式化文档中被标记为不推荐使用。
https://wordpress.stackexchange.com/questions/82542
复制相似问题