WooCommerce provides various methods to retrieve detailed information about an order using its order ID. To access order details, you can use the WC_Order and WC_Abstract_Order classes.
In WooCommerce versions 3.0 and above, the following changes were introduced:
To retrieve order details, follow these steps:
Get an instance of the WC_Order object:
$order = wc_get_order( $order_id );
Use getter methods to access specific order properties:
$order_id = $order->get_id(); // Order ID $status = $order->get_status(); // Order status $currency = $order->get_currency(); // Currency used $payment_method = $order->get_payment_method(); // Payment method ID $date_created = $order->get_date_created(); // Date created (WC_DateTime object)
To get order items and their details:
Iterate through the $order->get_items() collection:
foreach ($order->get_items() as $item_key => $item) { $product_id = $item->get_product_id(); // Product ID $quantity = $item->get_quantity(); // Quantity $total = $item->get_total(); // Total price }
Use WC_Order_Item_Product methods to access product-specific information:
$product = $item->get_product(); // WC_Product object $product_type = $product->get_type(); // Product type
By utilizing these methods, you can easily access detailed information about WooCommerce orders and order items.
The above is the detailed content of How to Retrieve Detailed WooCommerce Order Information Using Order ID?. For more information, please follow other related articles on the PHP Chinese website!