You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WooCommerce订单导出CSV税码字段PHP代码修正请求

修正WooCommerce订单导出税务代码逻辑

你需要实现的逻辑是当订单的shipping_country等于"GB"时,tax_code设为"T1",否则设为"T0",原代码存在两处关键错误,以下是修正后的代码:

$tax_code = "";
if ($order->shipping_country === "GB") {
    $tax_code = "T1";
} else {
    $tax_code = "T0";               
}

$order_data['tax'] = $tax_code; 

错误说明与修正点:

  • 原代码错误使用赋值符号=,应该用严格比较符号===(同时匹配值与数据类型,避免类型转换引发的意外问题)
  • 无需使用in_array(),因为shipping_country是单个字符串值,直接做相等判断即可

你也可以用更简洁的三元表达式写法,效果完全一致:

$tax_code = ($order->shipping_country === "GB") ? "T1" : "T0";
$order_data['tax'] = $tax_code;

内容的提问来源于stack exchange,提问作者Craig Simpson

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.24 23:19:01