WooCommerce 3.0+ – Get order details

 · 3 Minuten Lesezeit

What worked in WooCommerce 2.5. and 2.6. doesn’t work in version 3.0 of WooCommerce anymore, because they changed properties permissions. So but how does it work now?

You will need to use specific getter and setter methods to access order items of WooCommerce.

The basics

We get the instance of the WC_Order by its public ID. Then we can access the data using getter methods.

// Get instance of the WC_Order object
$order = wc_get_order($order_id); // Returns WC_Order

// Get the order ID
$order_id = $order->get_id();

// Get the customer ID
$customer_id = $order->get_customer_id(); //Returns integer


Access order properties

// Get instance of the WC_Order object
$order = wc_get_order($order_id); // Returns WC_Order

// Get order data
$order_data = $order->get_data(); // Returns Order Data array

// All useful order data
// Starting data that is directly accessible
$order_id = $order_data['id'];
$order_parent_id = $order_data['parent_id'];
$order_status = $order_data['status'];
$order_currency = $order_data['currency'];
$order_version = $order_data['version'];
//Payment info
$order_payment_method = $order_data['payment_method'];
$order_payment_method_title = $order_data['payment_method_title'];
//Date
$order_timestamp_created = $order_data['date_created']->getTimestamp();
$order_timestamp_modified = $order_data['date_modified']->getTimestamp();
//Amounts & discounts
$order_discount_total = $order_data['discount_total'];
$order_discount_tax = $order_data['discount_tax'];
$order_shipping_total = $order_data['shipping_total'];
$order_shipping_tax = $order_data['shipping_tax'];
$order_total = $order_data['cart_tax'];
$order_total_tax = $order_data['total_tax'];
$order_customer_id = $order_data['customer_id'];

//Billing information, accessible through $order_data['billing']
$order_billing_first_name = $order_data['billing']['first_name'];
$order_billing_last_name = $order_data['billing']['last_name'];
$order_billing_company = $order_data['billing']['company'];
$order_billing_address_1 = $order_data['billing']['address_1'];
$order_billing_address_2 = $order_data['billing']['address_2'];
$order_billing_city = $order_data['billing']['city'];
$order_billing_state = $order_data['billing']['state'];
$order_billing_postcode = $order_data['billing']['postcode'];
$order_billing_country = $order_data['billing']['country'];
$order_billing_email = $order_data['billing']['email'];
$order_billing_phone = $order_data['billing']['phone'];

//Shipping information, acessible through $order_data['shipping']
$order_shipping_first_name = $order_data['shipping']['first_name'];
$order_shipping_last_name = $order_data['shipping']['last_name'];
$order_shipping_company = $order_data['shipping']['company'];
$order_shipping_address_1 = $order_data['shipping']['address_1'];
$order_shipping_address_2 = $order_data['shipping']['address_2'];
$order_shipping_city = $order_data['shipping']['city'];
$order_shipping_state = $order_data['shipping']['state'];
$order_shipping_postcode = $order_data['shipping']['postcode'];
$order_shipping_country = $order_data['shipping']['country'];