Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i access current woocommerce order shipping method id?

I have found method

$order->get_shipping_method() 

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

like image 858
belfort1 Avatar asked Sep 30 '14 17:09

belfort1


People also ask

How do I find the current order ID in WooCommerce?

Current method: The current way of accomplishing this is by using this function: $order->get_id(); That should return the order id without "#".

How do I get WooCommerce order?

Using some WC_Order and WC_Abstract_Order methods (example): // Get an instance of the WC_Order object (same as before) $order = wc_get_order( $order_id ); $order_id = $order->get_id(); // Get the order ID $parent_id = $order->get_parent_id(); // Get the parent order ID (for subscriptions…)


2 Answers

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.

like image 124
belfort1 Avatar answered Oct 21 '22 18:10

belfort1


$shipping_method = @array_shift($order->get_shipping_methods());
$shipping_method_id = $shipping_method['method_id'];
like image 25
AndreyP Avatar answered Oct 21 '22 19:10

AndreyP