Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve Shipping Method of an Order in WooCommerce?

Tags:

I am developing an eCommerce website on Wordpress using WooCommerce. I want to retrieve and display the 'Shipping Method' (i.e. Delivery or Collection etc.), that the customer had selected at the time of checkout, on the Order Confirmation page (i.e. after payment).

I am trying to do this using get_post_meta($post_id, $key, $single) function. I am unable to do so as I don't know the $key value.

I tried the following code (within php tag):

echo get_post_meta( $order_id, 'shipping_method', true );

But it returns a blank value (no display on the page). I am assuming that I am using incorrect $key.

I am open to suggestions to use some other (simpler) method also to achieve this.

like image 241
M. Khan Avatar asked Aug 10 '19 18:08

M. Khan


People also ask

How would you obtain a customer's order details from WooCommerce?

One way is to simply go to the “Customers” page in your WordPress admin panel. From there, you can click on any customer to view their complete details. Another way to get customer details is through the WooCommerce REST API. This allows you to programmatically get information about customers, orders, etc.

What is shipping method in WooCommerce?

WooCommerce offers three types of shipping methods by default. They include flat rate shipping, free shipping, and local pickup. Using flat rate shipping, you can ship items to your buyers at a flat or standard rate per item, order, or shipping class.


1 Answers

Since WooCommerce 3, if you want to get the shipping formatted method title(s), you can better use WC_Order method get_shipping_method() like:

// Get the WC_Order object from the Order ID
$order = wc_get_order( $order_id );

// Output the shipping method(s) formatted method title(s)
echo $order->get_shipping_method();

For other shipping item details see the following threads:

  • Get orders shipping method details in WooCommerce 3
  • Show Shipping Method data on the Order edit pages in WooCommerce
like image 156
LoicTheAztec Avatar answered Oct 12 '22 22:10

LoicTheAztec