How to get WooCommerce order details?

You are currently viewing How to get WooCommerce order details?

How to get WooCommerce order details?

To retrieve the details of an order in WooCommerce, you will need to use the wc_get_order function. This function accepts the order ID as a parameter and returns an instance of the WC_Order class, which you can use to access the order details.

Here’s an example of how you can use this function to retrieve and display the details of an order:

Copy code$order_id = 123;
$order = wc_get_order( $order_id );

echo 'Order Number: ' . $order->get_order_number() . '<br>';
echo 'Order Total: ' . $order->get_formatted_order_total() . '<br>';
echo 'Payment Method: ' . $order->get_payment_method_title() . '<br>';

$items = $order->get_items();
foreach ( $items as $item ) {
    $product = $item->get_product();
    echo 'Product Name: ' . $product->get_name() . '<br>';
    echo 'Product Quantity: ' . $item->get_quantity() . '<br>';
    echo 'Product Total: ' . $item->get_total() . '<br>';
}

This code will retrieve the order with the specified ID, and then display the order number, total, and payment method. It will also loop through the items in the order and display the name, quantity, and total for each product.

if you need any help in WordPress development, click here

Leave a Reply