Replace WooCommerce Class

WooCommerce has a class “get_shipping_to_display()” in /wp-content/plugins/woocommerce/classes/class-wc-order.php, that keeps outputting $36 in my invoices (using the Print Invoice & Packing List plugin) as the value for shipping… regardless of what the shipping out is actually.

I’ve narrowed it down to that class, as using “get_shipping()” displays the actual shipping price.

Read More

I don’t want to modify WooCommerce core files (so as not to cause problems with updates later on), so how do I go about replacing that class with my own class in functions.php so I can try and narrow down what is causing the issue… and what would that look like?

Related posts

Leave a Reply

1 comment

  1. The last line in the function get_shipping_to_display() is:

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

    That means that if you create a filter on woocommerce_order_shipping_to_display you can ultimately output whatever you want (though technically contents of that function will still run first). The $shipping variable contains the text output you are seeing now and $this will have all the properties of the class, including the order $id, $status, etc which you could use to do whatever lookups/calculations you want.