本文介绍了仅在 WooCommerce 前端将小数样式化为大写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望您能就具体案例提供帮助.我能够在我的 WooCommerce 商店中完全按照我的意愿制作价格小数点的样式.
I'd like your help for a specific case. I was able to make the stylization of the price decimals exactly as I wished on my WooCommerce store.
但是,问题是现在这段代码也适用于我的 WooCommerce 后端.你知道我怎样才能让下面的代码不影响 WooCommerce 后端页面吗?
However, the problem is that now this code also applies for my WooCommerce backend. Do you know how I could make that the below code do not impact the WooCommerce backend pages?
/**
* 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 ), 0, $decimal_separator, $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%;
}
推荐答案
新线程:小数的自定义样式会破坏默认的 WooCommerce 计算
更新 - 只需使用条件标签 is_admin()
如下:
Updated - Simply use the conditional tag is_admin()
as follow:
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 ), 0, $decimal_separator, $thousand_separator );
$decimal = sprintf( '%02d', ( $price - intval( $price ) ) * 100 );
return $unit . '<sup>' . $decimal . '</sup>';
}
return $formatted_price;
}
文档:WordPress 条件标签 is_admin()
这篇关于仅在 WooCommerce 前端将小数样式化为大写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!