How can i access current woocommerce order shippin

2019-02-03 11:41发布

问题:

I have found method

$order->get_shipping_method() 

to access the name, but i want to retrieve the id instead of name?

回答1:

thought i'd share how I solved this if someone runs into the same problem as me. I have WC_Order in the $order variable.

$order->get_items( 'shipping' );

This gives me an array with name, type, method_id, cost and taxes.



回答2:

$shipping_method = @array_shift($order->get_shipping_methods());
$shipping_method_id = $shipping_method['method_id'];