I'm trying to get the shipping method or cost of shipping for a WooCommerce order - I'm writing a custom email template that is different depending on free delivery vs paid delivery.
I found a function called get_total_shipping()
, but this is now deprecated and I cannot find a replacement - does one exist?
I've noticed that the shipping amount is stored in a hidden meta field (_order_shipping
), which I can access, but I worry that this might break on future WooCommerce updates.
Since Woocommerce 3 get_total_shipping()
method is replaced by get_shipping_total()
.
So there is actually 2 available CRUD getters methods for shipping totals in WC_Abstract_Order
Class that can be used on the WC_Order
instance object:
get_shipping_total()
that is the shipping total excluding taxesget_shipping_tax()
that is the shipping taxes totalSo you will use them with the $order
variable object simply this way:
$shipping_total = $order->get_shipping_total();
$shipping_tax = $order->get_shipping_tax();
There is also get_shipping_to_display()
method that will output the formatted shipping total.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With