Woocmmerce仅将CSS应用于小数

时间:2019-05-17 16:25:05

标签: css woocommerce styles wpml

我正试图找到一个函数,该函数将使Woocommerce价格中的小数部分具有自己的CSS类,因此我可以对价格的非小数部分应用与样式不同的样式。我有多语言和多币种的网站。

我找到了可以满足我需求的代码,但是它的编码方式可以将货币符号替换为巴西符号,并且因为我不知道如何编码,所以无法修改代码来满足我的需求。

谢谢。

2 个答案:

答案 0 :(得分:0)

在小数点后添加<span>并为其创建一个类:

HTML:

<div name="price">
    &#36; 99.<span class="decimals">99<span>
</div>

CSS:

.decimals {
    /* The style you want for the decimals goes here */
}

答案 1 :(得分:0)

您需要使用formatted_woocommerce_price过滤器。检查代码示例。您可以将sub更改为特定类所需的任何HTML元素。

add_filter( 'formatted_woocommerce_price', 'style_decimal_price', 10, 5 );
function style_decimal_price( $formatted_price, $price, $decimal_places, $decimal_separator, $thousand_separator ) {

    $unit    = number_format( intval( $price ), 0, $decimal_separator, $thousand_separator );
    $decimal = sprintf( '%02d', ( $price - intval( $price ) ) * 100 );

    return $unit . '<sub class="custom-decimal">' . $decimal_separator. $decimal . '</sub>';
}