To get order details in WooCommerce, you can use the wc_get_order() function to retrieve the order object, and then use the methods and properties of that object to access the order’s details. For example, to get the order ID, you can use $order->get_id(). To get the customer’s email, you can use $order->get_billing_email(). To get the order’s line items, you can use $order->get_items().

Here is an example of how you can use the wc_get_order() function to get the order details for an order with an ID of 100:

$order = wc_get_order( 100 );
$order_id = $order->get_id();
$customer_email = $order->get_billing_email();
$line_items = $order->get_items();

You can also use the WC_Order_Factory class to get the order details, the code will be look like this:

$order = WC_Order_Factory::get_order( $order_id );

You can also use the get_post_meta() function to retrieve custom order meta data, for example,

$custom_meta = get_post_meta($order_id, '_custom_meta_key', true);

You can also use the get_order_item_meta() function to retrieve the item meta data, for example:

$item_meta = get_order_item_meta( $item_id, '_meta_key' );

And many other methods available in the WC_Order class which can be used to retrieve different types of order details.

(Visited 128 times, 1 visits today)
Was this article helpful?
YesNo
Close Search Window