WooCommerce allows us to retrieve extensive order details using the wc_get_order() function. This function accepts an order ID as an argument and returns a WC_Order object.
Using the WC_Order object, you can access various order-related details through its methods. Here's an example:
$order = wc_get_order( $order_id ); $order_id = $order->get_id(); // Get the order ID $order_status = $order->get_status(); // Get the order status $order_total = $order->get_total(); // Get the order total
Version 3.0 Updates:
Accessing Order Items:
You can iterate through order items and access detailed information for each one:
foreach ($order->get_items() as $item_key => $item) { $product_id = $item->get_product_id(); $quantity = $item->get_quantity(); $line_subtotal = $item->get_subtotal(); }
Retrieving Billing and Shipping Information:
The WC_Order object also provides access to billing and shipping information:
$billing_first_name = $order->get_billing_first_name(); $shipping_country = $order->get_shipping_country();
Order Data Properties:
Using the get_data() method, you can access order data properties as an array of values:
$order_data = $order->get_data(); $order_id = $order_data['id']; $order_status = $order_data['status'];
By utilizing these methods and accessing the appropriate data structures, you can effectively retrieve various order details in WooCommerce.
The above is the detailed content of How Can I Retrieve WooCommerce Order Details Using the Order ID?. For more information, please follow other related articles on the PHP Chinese website!