Since I already have access to the order ID and the list of orders, how do I get access to each order fee from each each order?
I have the following, but where and how do I insert that inside my existing code, allowing me to add it as an $orderList
index?
foreach( $orderID->get_items('fee') as $item_id => $item_fee ){
// fee name
$fee_name = $item_fee->get_name();
// fee total amount
$fee_total = $item_fee->get_total();
// fee total tax amount
$fee_total_tax = $item_fee->get_total_tax();
}
I need to be able to use the above with the code below.
function GetOrderList() {
$query = new WC_Order_Query( array(
'limit' => 100,
'orderby' => 'date',
'order' => 'DESC',
'return' => 'ids',
) );
$orders = $query->get_orders();
$orderList = array();
$index = 0;
foreach ( $orders as $orderID ) {
$order = new WC_Order($orderID);
$order_data = $order->get_data();
$orderList[$index]['order_id'] = $orderID;
$orderList[$index]['name'] = $order->get_billing_first_name().' '.$order->get_billing_last_name();
$orderList[$index]['email'] = $order->get_billing_email();
$orderList[$index]['phone'] = $order->get_billing_phone();
$orderList[$index]['note'] = $order->get_customer_note();
$orderList[$index]['order_status'] = $order->get_status();
$orderList[$index]['total_price'] = $order->get_total();
// how do I get this to work?
$orderList[$index]['fee'] = $order->$fee_total;
$index++;
}
return $orderList;
}
I modified your code a bit.
To add the fee data to the array, returned from your custom function, you can use:
Result: