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

如何为WooCommerce订单/购物车统一添加400g包装重量

给WooCommerce购物车总重量添加固定400克的简便方法
  • 直接通过WooCommerce内置钩子实现,无需冗余功能。将以下代码添加到主题的functions.php文件或自定义插件中:
    add_filter( 'woocommerce_cart_contents_weight', 'add_fixed_weight_to_cart' );
    function add_fixed_weight_to_cart( $weight ) {
        // 根据商店重量单位调整数值:克单位填400,千克单位填0.4
        $fixed_addition = 400;
        return $weight + $fixed_addition;
    }
    
  • 关键说明:
    • woocommerce_cart_contents_weight钩子专门用于修改购物车的总重量计算结果
    • 务必根据你后台设置的重量单位调整$fixed_addition的数值,避免重量计算错误
  • 验证方式:添加商品到购物车后,查看购物车页面的重量统计项,确认已追加400克,运费插件会自动基于更新后的总重量计算运费

内容的提问来源于stack exchange,提问作者Andreas Damberg

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.16 06:20:53