如何解决小数位数的样式化仅在WooCommerce前端中为大写
在特定情况下,我需要您的帮助。我能够完全按照我在WooCommerce商店上的期望来对价格小数进行样式化。
但是,问题在于现在此代码也适用于我的WooCommerce后端。您知道如何使以下代码不影响WooCommerce后端页面吗?
/**
* ADJUST THE DECIMALS STYLE AS UPPERCASE (COMPLEMENTARY TO CSS)
*/
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 ),$thousand_separator );
$decimal = sprintf( '%02d',( $price - intval( $price ) ) * 100 );
return $unit . '<sup>' . $decimal . '</sup>';
}
/* GENERAL - ADJUST THE DECIMALS STYLE AS UPPERCASE (COMPLEMENTARY TO PHP) */
.price .amount {
font-size: 120%;
}
.sub,sup {
margin-left: 2px;
margin-right: 2px;
font-size: 60%;
}
解决方法
新主题:Custom stylization of decimals breaks default WooCommerce calculations
已更新-只需按如下所述使用条件标签is_admin()
:
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 ) {
// Not on backend
if ( ! is_admin() ) {
$unit = number_format( intval( $price ),$thousand_separator );
$decimal = sprintf( '%02d',( $price - intval( $price ) ) * 100 );
return $unit . '<sup>' . $decimal . '</sup>';
}
return $formatted_price;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。