替换WooCommerce类

时间:2013-11-07 02:32:33

标签: php wordpress woocommerce

WooCommerce在/wp-content/plugins/woocommerce/classes/class-wc-order.php中有一个“get_shipping_to_display()”类,它会在我的发票中输出36美元(使用“打印发票和装箱单”插件)作为运输的价值......无论出货实际是什么。

我已将其缩小到该级别,因为使用“get_shipping()”会显示实际的运费。

我不想修改WooCommerce核心文件(以免以后导致更新问题),所以如何在functions.php中用我自己的类替换该类,以便我可以尝试缩小范围是什么导致了这个问题......那会是什么样子?

1 个答案:

答案 0 :(得分:1)

函数get_shipping_to_display()的最后一行是:

return apply_filters( 'woocommerce_order_shipping_to_display', $shipping, $this );

这意味着如果你在woocommerce_order_shipping_to_display上创建一个过滤器,你最终可以输出任何你想要的东西(尽管技术上该功能的内容仍会先运行)。 $shipping变量包含您现在看到的文本输出,$this将包含该类的所有属性,包括您可以使用的订单$id$status等做你想做的任何查找/计算。