问题描述
在特定情况下,我需要您的帮助。我能够完全按照我在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;
}