php - Woocommerce - 在结帐期间更改总文本并添加费用
问题描述
我正在尝试对结帐页面进行简单的文本更新。
例如,当前显示的总数:
135.65 美元(包括 10.35 美元 GST)
但由于推车的总重量超过 25 公斤,我想添加 2.5 美元的额外费用,我现在希望它显示如下:
135.65 美元(包括 10.35 美元的商品及服务税以及处理和包装(2.5 美元))
实际上,我之前让代码可以工作,但在最新的 Woocommerce 更新之后,我的代码似乎不再工作了。
这里是:
add_filter( 'gettext', function( $translation, $text, $domain ) {
global $handlingfee;
global $cartweight;
if ($cartweight >= 25 && $cartweight <= 39)
$handlingfee = 2.50;
if ($cartweight >= 40 && $cartweight <= 59)
$handlingfee = 5.00;
if ($cartweight >= 60 && $cartweight <= 79)
$handlingfee = 7.50;
if ($cartweight >= 80 && $cartweight <= 99)
$handlingfee = 10.00;
if ($cartweight >= 100 && $cartweight <= 119)
$handlingfee = 12.50;
if ($cartweight >= 120 && $cartweight <= 139)
$handlingfee = 15.00;
if ($cartweight >= 140 && $cartweight <= 159)
$handlingfee = 17.50;
if ($cartweight >= 160 && $cartweight <= 179)
$handlingfee = 20.00;
if ($cartweight >= 180 && $cartweight <= 199)
$handlingfee = 22.50;
if ($cartweight >= 200 && $cartweight <= 219)
$handlingfee = 25.00;
if ($cartweight >= 25) {
$processingfeetext = ' and <b>$' . $handlingfee . '</b> H&P';
}
if ( $domain == 'woocommerce' ) {
if ( $text == '(includes %s)' ) { $translation = '(includes %s' . $processingfeetext . ')'; }
}
return $translation;
}, 10, 3 );
add_filter( 'woocommerce_calculated_total', 'change_calculated_total', 10, 2 );
add_filter( 'woocommerce_calculated_total', 'change_calculated_total', 10, 2 );
function change_calculated_total( $total, $cart ) {
global $handlingfee;
global $cartweight;
if ($handlingfee > 0){
return $total + $handlingfee;
}
else
{
return $total;
}
}
任何帮助将不胜感激。
解决方案
推荐阅读
- python - 升级 Ipython 时出现问题(prompt_toolkit 不兼容)
- centos - gnome 禁用“以其他用户身份登录”链接
- php - 如何使用查询从 MySQL 数据库中删除 id
- ssl - 如何从不使用默认 WLAN 代理设置的 apk 捕获和解码 ssl 流量
- javascript - 如何使用ajax一起发送模态表单和普通表单
- database - 如何对该模式进行分类?
- tensorflow - 有谁知道如何关闭 tensorflow meta_optimizer.cc:334 中的 LOG(INFO) 信息
- multithreading - Perl 简单的网络服务器不能同时处理多个请求
- php - 使用 PHP 从 2 个具有相同 ID 的表中加入 MySQL
- php - PHP系统,exec,passthru返回码127