仅对Woocmerce的小数应用CSS

仅对Woocmerce的小数应用CSS,css,woocommerce,styles,wpml,Css,Woocommerce,Styles,Wpml,我试图找到一个函数,使Woocommerce prices中的小数点位置有自己的CSS类,这样我就可以对价格的非小数部分应用不同的样式。我有多语言和多货币的网站 我找到了一个代码,它符合我的要求,但它的编码方式将取代巴西符号的货币符号,因为我不知道如何编码自己,我无法修改代码以适应我的需要 提前感谢。在小数处添加一个,并为它们创建一个类: HTML: <div name="price"> &#36; 99.<span class="decimals">99

我试图找到一个函数,使Woocommerce prices中的小数点位置有自己的CSS类,这样我就可以对价格的非小数部分应用不同的样式。我有多语言和多货币的网站

我找到了一个代码,它符合我的要求,但它的编码方式将取代巴西符号的货币符号,因为我不知道如何编码自己,我无法修改代码以适应我的需要

提前感谢。

在小数处添加一个
,并为它们创建一个类:

HTML:

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

您需要使用
formatted\u woodcommerce\u 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>';
}
添加过滤器('formatted\u\u commerce\u price','style\u decimal\u price',10,5);
函数样式\u十进制\u价格($formatted\u price,$price,$decimal\u places,$decimal\u separator,$1000\u separator){
$unit=数字\格式(intval($price),0,$decimal\分隔符,$1000\分隔符);
$decimal=sprintf('%02d',($price-intval($price))*100);
返回$unit.'.$decimal_分隔符.$decimal.';
}

Hi Matheus,我不能给小数加上一个空格,因为woocommerce中的价格不是你能做到的,或者至少我不知道如何做到,那样添加css。不是像html纯文本,我可以修改。。。我不知道这是否有意义。转到
wp content
中的文件,浏览
模板。整个路径是:
wp-content/plugins/woocommerce/templates/
。在那里,您将拥有全局文件夹和购物车文件夹,其中可能有.PHP文件,您可以在其中编辑和编码HTML部分。然后,只需找到购物车或全局的相关.CSS文件,并将样式应用于在
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>';
}