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

WooCommerce:如何为特定品牌实现按订单总价计算运费?

针对特定品牌按订单总价计算运费的解决方案

自定义代码方案(以WooCommerce为例)

  1. 先给目标零售商的所有产品统一设置产品品牌属性(或自定义分类/标签),比如品牌名设为TargetBrand。
  2. 在主题的functions.php文件或自定义代码插件中添加以下代码:
add_filter('woocommerce_package_rates', 'target_brand_price_based_shipping', 10, 2);
function target_brand_price_based_shipping($rates, $package) {
    // 替换为你的目标品牌名称
    $target_brand = 'TargetBrand';
    $target_total = 0;
    $has_target_items = false;

    // 统计购物车中目标品牌商品的总价
    foreach ($package['contents'] as $item_id => $item) {
        $product = $item['data'];
        // 若用产品分类,替换为 has_term('目标分类slug', 'product_cat', $product->get_id())
        if ($product->get_attribute('brand') === $target_brand) {
            $target_total += $item['line_total'];
            $has_target_items = true;
        }
    }

    if (!$has_target_items) {
        return $rates;
    }

    // 自定义价格阶梯运费规则,按需修改
    $shipping_cost = 0;
    if ($target_total < 50) {
        $shipping_cost = 5.99;
    } elseif ($target_total >= 50 && $target_total < 100) {
        $shipping_cost = 3.99;
    } else {
        $shipping_cost = 0; // 满100免运费
    }

    // 替换为你给该品牌设置的配送类别ID或slug
    $target_shipping_method = 'target-brand-shipping';
    foreach ($rates as $rate_id => $rate) {
        if ($rate->get_shipping_method_id() === $target_shipping_method) {
            $rates[$rate_id]->set_cost($shipping_cost);
            // 同步税费(若启用税费则保留)
            $taxes = array();
            foreach ($rates[$rate_id]->get_taxes() as $tax_id => $tax) {
                $taxes[$tax_id] = $shipping_cost * ($tax / 100);
            }
            $rates[$rate_id]->set_taxes($taxes);
        }
    }

    return $rates;
}
  • 注意事项:
    • 代码中的品牌名、配送类别标识、运费阶梯规则都要替换为你实际的配置
    • 修改主题文件前建议先备份,或者用自定义代码插件(如Code Snippets)来添加代码,避免主题更新丢失

插件方案(无需代码)

如果不熟悉代码,推荐用可视化配置的插件:

  • WooCommerce Advanced Shipping:支持按产品品牌、分类、订单金额等多维度组合设置运费规则,后台直接拖拽配置,能精准匹配目标品牌的运费需求。
  • Table Rate Shipping for WooCommerce:专门用于阶梯运费设置,可单独创建针对特定品牌的规则,按订单总价区间设定对应运费,操作门槛低。

核心操作步骤:

  1. 安装激活插件后,进入WooCommerce的「配送」设置页面
  2. 创建新的运费规则,条件选择「产品品牌」并指定目标零售商品牌
  3. 设置运费计算方式为「订单总价」,添加不同价格区间对应的运费金额
  4. 将规则关联到你为该品牌设置的专属配送类别即可

内容的提问来源于stack exchange,提问作者Mr. T k

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.16 06:45:35