我正在尝试获取WooCommerce订单的送货方式或运费 - 我正在编写一个不同的自定义电子邮件模板,具体取决于免费送货与付费送货 .
我找到了一个名为 get_total_shipping() 的函数,但现在已弃用,我找不到替代品 - 是否存在?
get_total_shipping()
我注意到运费金额存储在一个隐藏的元字段( _order_shipping )中,我可以访问,但我担心这可能会破坏未来的WooCommerce更新 .
_order_shipping
自Woocommerce 3 get_total_shipping() method is replaced by get_shipping_total() .
因此,WC_Abstract_Order类中的 shipping totals 实际上有两个可用的CRUD getters方法,可用于WC_Order实例对象:
get_shipping_total() 这是不含税的运费总额
get_shipping_total()
get_shipping_tax() 这是运费税总额
get_shipping_tax()
因此,您将以这种方式将它们与 $order 变量对象一起使用:
$order
$shipping_total = $order->get_shipping_total(); $shipping_tax = $order->get_shipping_tax();
还有get_shipping_to_display()方法将输出格式化的运输总额 .
1 回答
自Woocommerce 3 get_total_shipping() method is replaced by get_shipping_total() .
因此,WC_Abstract_Order类中的 shipping totals 实际上有两个可用的CRUD getters方法,可用于WC_Order实例对象:
get_shipping_total()
这是不含税的运费总额get_shipping_tax()
这是运费税总额因此,您将以这种方式将它们与
$order
变量对象一起使用:还有get_shipping_to_display()方法将输出格式化的运输总额 .