繁体   English   中英

将 wc_price(格式化价格)放在输入文本 woocommerce 中

[英]place wc_price (formatted price) inside an input text woocommerce

我有一个文本输入字段,它的值是一个简码,显示客户在我们商店花费的总价格。 此总计以 wc_price 格式返回,以便它尊重带有“,”和货币符号的十进制格式。

我遇到的问题是,当短代码返回值时,它返回格式化的价格,在输入文本内显示 label,在输入文本外显示总价。

在此处输入图像描述

如果我返回没有 wc_price 格式的值,则该值在输入文本中正确显示,但小数点显示为“。” 而不是“,”,货币也不会显示。

如何才能在输入文本中返回正确的值并且不显示 span 标签?

这是我获取客户累积的总费用并创建简码的代码:

add_shortcode('user_total_spent', 'get_user_total_spent');
function get_user_total_spent( $atts ) {
    extract( shortcode_atts( array(
        'user_id' => get_current_user_id(),
    ), $atts, 'user_total_spent' ) );

    if( $user_id > 0 ) {
        $customer = new WC_Customer( $user_id ); // Get WC_Customer Object

        $total_spent = $customer->get_total_spent(); // Get total spent amount

        return wc_price( $total_spent ); // return formatted total spent amount
    }
}

这是我的代码,用于显示带有总计值的输入文本:

add_action( 'woocommerce_account_informes_endpoint', 'ani_populate_informes_page' );
function ani_populate_informes_page() {
    $totalGasto = do_shortcode('[user_total_spent]');
    echo '
        <h3>Informes</h3>
        <p>Aquí puedes encontrar un informe del gasto que has realizado en nuestra tienda.</p>
        
        <div>
            <label for="gastototalclientemicuenta">Gasto total:</label>
            <input type="text" id="gastototalclientemicuenta" name="gastototalclientemicuenta" value="'. $totalGasto .'" readonly> <br>
        </div>
        
        ';
  }

使用wc_format_localized_price function 代替wc_price

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM