1// Get an instance of the WC_Order object
2$order = wc_get_order( $order_id );
3
4$order_data = $order->get_data(); // The Order data
5
6$order_id = $order_data['id'];
7$order_parent_id = $order_data['parent_id'];
8$order_status = $order_data['status'];
9$order_currency = $order_data['currency'];
10$order_version = $order_data['version'];
11$order_payment_method = $order_data['payment_method'];
12$order_payment_method_title = $order_data['payment_method_title'];
13$order_payment_method = $order_data['payment_method'];
14$order_payment_method = $order_data['payment_method'];
15
16## Creation and modified WC_DateTime Object date string ##
17
18// Using a formated date ( with php date() function as method)
19$order_date_created = $order_data['date_created']->date('Y-m-d H:i:s');
20$order_date_modified = $order_data['date_modified']->date('Y-m-d H:i:s');
21
22// Using a timestamp ( with php getTimestamp() function as method)
23$order_timestamp_created = $order_data['date_created']->getTimestamp();
24$order_timestamp_modified = $order_data['date_modified']->getTimestamp();
25
26$order_discount_total = $order_data['discount_total'];
27$order_discount_tax = $order_data['discount_tax'];
28$order_shipping_total = $order_data['shipping_total'];
29$order_shipping_tax = $order_data['shipping_tax'];
30$order_total = $order_data['cart_tax'];
31$order_total_tax = $order_data['total_tax'];
32$order_customer_id = $order_data['customer_id']; // ... and so on
33
34## BILLING INFORMATION:
35
36$order_billing_first_name = $order_data['billing']['first_name'];
37$order_billing_last_name = $order_data['billing']['last_name'];
38$order_billing_company = $order_data['billing']['company'];
39$order_billing_address_1 = $order_data['billing']['address_1'];
40$order_billing_address_2 = $order_data['billing']['address_2'];
41$order_billing_city = $order_data['billing']['city'];
42$order_billing_state = $order_data['billing']['state'];
43$order_billing_postcode = $order_data['billing']['postcode'];
44$order_billing_country = $order_data['billing']['country'];
45$order_billing_email = $order_data['billing']['email'];
46$order_billing_phone = $order_data['billing']['phone'];
47
48## SHIPPING INFORMATION:
49
50$order_shipping_first_name = $order_data['shipping']['first_name'];
51$order_shipping_last_name = $order_data['shipping']['last_name'];
52$order_shipping_company = $order_data['shipping']['company'];
53$order_shipping_address_1 = $order_data['shipping']['address_1'];
54$order_shipping_address_2 = $order_data['shipping']['address_2'];
55$order_shipping_city = $order_data['shipping']['city'];
56$order_shipping_state = $order_data['shipping']['state'];
57$order_shipping_postcode = $order_data['shipping']['postcode'];
58$order_shipping_country = $order_data['shipping']['country'];
1// Get an instance of the WC_Order object (same as before)
2$order = wc_get_order( $order_id );
3
4$order_id = $order->get_id(); // Get the order ID
5$parent_id = $order->get_parent_id(); // Get the parent order ID (for subscriptions…)
6
7$user_id = $order->get_user_id(); // Get the costumer ID
8$user = $order->get_user(); // Get the WP_User object
9
10$order_status = $order->get_status(); // Get the order status
11$currency = $order->get_currency(); // Get the currency used
12$payment_method = $order->get_payment_method(); // Get the payment method ID
13$payment_title = $order->get_payment_method_title(); // Get the payment method title
14$date_created = $order->get_date_created(); // Get date created (WC_DateTime object)
15$date_modified = $order->get_date_modified(); // Get date modified (WC_DateTime object)
16
17$billing_country = $order->get_billing_country(); // Customer billing country
18
19// ... and so on ...
1 public function get_sum_of_paid_orders( int $user_id ): int {
2
3 $customer_orders = [];
4 foreach ( wc_get_is_paid_statuses() as $paid_status ) {
5 $customer_orders += wc_get_orders( [
6 'type' => 'shop_order',
7 'limit' => - 1,
8 'customer_id' => $user_id,
9 'status' => $paid_status,
10 ] );
11 }
12
13 $total = 0;
14 foreach ( $customer_orders as $order ) {
15 $total += $order->get_total();
16
17 // your code is here
18 }
19
20 return $total;
21 }
22