我在网上商店使用WooCommerce。我在管理面板中将价格设置为美元。
如何为前端用户以比特币显示该价格?
我将在脚本中读取当前的比特币价值,并将该美元金额转换为BTC。
$backendPrice = 1000.00
$bitcoinPrice = 500.00
$displayPrice = 2
这一系列的过滤器挂钩将完成以下工作:
if( !is_admin() )
{
add_filter( 'woocommerce_get_sale_price', 'bit_price', 10, 2 );
add_filter( 'woocommerce_get_regular_price', 'bit_price', 10, 2 );
add_filter( 'woocommerce_get_price', 'bit_price', 10, 2 );
add_filter( 'woocommerce_currency_symbol', function( $currency_symbol, $currency ) {
return 'Bits'; //$currency_symbol;
}, 10, 2 );
add_filter( 'woocommerce_currency', function( $currency ) {
return $currency;
});
}
function bit_price( $price, $product )
{
return $price * 0.5;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句