問題:
我需要在小數點下顯示單位。
所以我使用以下代碼分隔了小數部分。
但它顯示如下(單位在價格旁邊):
你能告訴我如何把單位放在小數下嗎,像這樣?前端 HTML 顯示:

<span class="price">
<span class="woocommerce-Price-amount amount">
<bdi><span class="woocommerce-Price-currencySymbol">$</span>2<sup>85</sup></bdi>
</span>
<span class="uom">ea</span>
</span>
單獨的小數部分(functions.php):
add_filter( 'formatted_woocommerce_price', 'ts_woo_decimal_price', 10, 5 );
function ts_woo_decimal_price( $formatted_price, $price, $decimal_places, $decimal_separator, $thousand_separator ) {
$unit = number_format( intval( $price ), 0, $decimal_separator, $thousand_separator );
$decimal = sprintf( 'd', ( $price - intval( $price ) ) * 100 );
return $unit . '<sup>' . $decimal . '</sup>';
}
添加單位(WooCommerce 度量單位插件:class-wc-uom-public.php):
public function wc_uom_render_output( $price ) {
global $post;
// Check if uom text exists.
$woo_uom_output = get_post_meta( $post->ID, '_woo_uom_input', true );
// Check if variable OR UOM text exists.
if ( $woo_uom_output ) :
$price = $price . ' <span >' . esc_attr( $woo_uom_output, 'woocommerce-uom' ) . '</span>';
return $price;
else :
return $price;
endif;
}
謝謝你。
uj5u.com熱心網友回復:
這是一個基于 CSS 的解決方案:
<style>
.price {
font-size: 5em;
}
sup {
font-size: .5em;
}
.uom {
position: relative;
left: -1.4em;
font-size: .5em;
}
</style>
當然,您需要使用字體大小和定位來滿足您的特定需求
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/355638.html
標籤:php WordPress的 求购 十进制 价钱
