Stylization of decimals as uppercase in WooCommerce frontend only(仅在 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 前端将小数样式化为大写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:仅在 WooCommerce 前端将小数样式化为大写


基础教程推荐
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 如何替换eregi() 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01