How to get WooCommerce Order details Items by Order Object wc_get_order

If you developing WooCommerce theme, you are integrating custom design with WooCommerce, or if you developing any custom WooCommerce extension. in case you need to get order details in any hook, or in any design block if you need to show order details. you can access order details by only using the order id with this function wc_get_order.  By using this you can get complete access to the order details. Like order total, How can I get the order items, order ID, customer ID, billing info, payment method, and total refunds. this post will explain “How can I get WooCommerce order details?”

How to get WooCommerce Order details Items by Order Object wc_get_order

Get Order Object

you can get an order object by order id, replace 12 with your order id:


$order_id= "12";

$order = wc_get_order($order_id);

Get order id and order key from object:

$order->get_id();
$order->get_order_key();
Get Order Items and Loop Item by item
foreach ( $order->get_items() as $item_id => $item ) {
   $product_id = $item->get_product_id();
   $variation_id = $item->get_variation_id();
   $product = $item->get_product();
   $product_name = $item->get_name();
   $tax = $item->get_subtotal_tax();
   $taxclass = $item->get_tax_class();
   $taxstat = $item->get_tax_status();
   $allmeta = $item->get_meta_data();
   $somemeta = $item->get_meta( 'meta_key', true );
   $product_type = $item->get_type();
   $quantity = $item->get_quantity();
   $subtotal = $item->get_subtotal();
   $total = $item->get_total();
}

Get Order Total and Subtotal

$order->get_line_subtotal();
$order->get_line_tax();
$order->get_line_total();

Get Order Payment Details

$order->get_payment_method();
$order->get_payment_method_title();
$order->get_transaction_id();

Get Order Shipping Details

$order->get_shipping_method();
$order->get_shipping_methods();
$order->get_shipping_to_display();

Get Order Activity Dates

$order->get_date_created();
$order->get_date_modified();
$order->get_date_completed();
$order->get_date_paid();

Get Customer ID and IP

$order->get_customer_id();
$order->get_user_id();
$order->get_user();
$order->get_customer_ip_address();
$order->get_customer_user_agent();
$order->get_created_via();
$order->get_customer_note();
$order->get_address_prop();

Get Customer Billing Address

$order->get_billing_first_name();
$order->get_billing_last_name();
$order->get_billing_company();
$order->get_billing_address_1();
$order->get_billing_address_2();
$order->get_billing_city();
$order->get_billing_state();
$order->get_billing_postcode();
$order->get_billing_country();
$order->get_billing_email();
$order->get_billing_phone();

Get Customer Shipping Address

$order->get_shipping_first_name();
$order->get_shipping_last_name();
$order->get_shipping_company();
$order->get_shipping_address_1();
$order->get_shipping_address_2();
$order->get_shipping_city();
$order->get_shipping_state();
$order->get_shipping_postcode();
$order->get_shipping_country();
$order->get_address();
$order->get_shipping_address_map_url();
$order->get_formatted_billing_full_name();
$order->get_formatted_shipping_full_name();
$order->get_formatted_billing_address();
$order->get_formatted_shipping_address();

Get Order Links and Status

$order->get_checkout_payment_url();
$order->get_checkout_order_received_url();
$order->get_cancel_order_url();
$order->get_cancel_order_url_raw();
$order->get_cancel_endpoint();
$order->get_view_order_url();
$order->get_edit_order_url();

That’s how you can complete your development. if you still face issues with getting the full order please let us know in the comment section. we will discuss it to solve it. Please join our Facebook page and youtube channel.

Add a Comment