Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function get_orders() {
- $result = array();
- $statuses = Order_Util::get_import_status_list();
- $current_language = get_locale();
- foreach ( wc_get_orders(
- array(
- 'status' => array_keys( $statuses ),
- 'limit' => -1,
- )
- ) as $order ) {
- $recipient = array(
- 'firstname' => Misc_Util::not_empty_or_null( Order_Util::get_shipping_first_name( $order ) ),
- 'lastname' => Misc_Util::not_empty_or_null( Order_Util::get_shipping_last_name( $order ) ),
- 'company' => Misc_Util::not_empty_or_null( Order_Util::get_shipping_company( $order ) ),
- 'addressLine1' => Misc_Util::not_empty_or_null( Order_Util::get_shipping_address_1( $order ) ),
- 'addressLine2' => Misc_Util::not_empty_or_null( Order_Util::get_shipping_address_2( $order ) ),
- 'city' => Misc_Util::not_empty_or_null( Order_Util::get_shipping_city( $order ) ),
- 'state' => Misc_Util::not_empty_or_null( Order_Util::get_shipping_state( $order ) ),
- 'postcode' => Misc_Util::not_empty_or_null( Order_Util::get_shipping_postcode( $order ) ),
- 'country' => Misc_Util::not_empty_or_null( Order_Util::get_shipping_country( $order ) ),
- 'phone' => Misc_Util::not_empty_or_null( Order_Util::get_billing_phone( $order ) ),
- 'email' => Misc_Util::not_empty_or_null( Order_Util::get_billing_email( $order ) ),
- );
- $products = array();
- foreach ( $order->get_items( 'line_item' ) as $item ) {
- do_action( 'woocommerce/cart_loop/start', $item );
- $product = array();
- $variation_id = $item['variation_id'];
- $product_id = ( '0' !== $variation_id && 0 !== $variation_id ) ? $variation_id : $item['product_id'];
- if ( ! Product_Util::is_product_virtual( $product_id ) ) {
- $product['weight'] = false !== Product_Util::get_product_weight( $product_id ) ? (float) Product_Util::get_product_weight( $product_id ) : null;
- $product['quantity'] = (int) $item['qty'];
- $product['price'] = Product_Util::get_product_price( $product_id );
- $product['description'] = array(
- $current_language => esc_html( Product_Util::get_product_description( $item ) ),
- );
- $products[] = $product;
- }
- do_action( 'woocommerce/cart_loop/end', $item );
- }
- $parcelpoint = Order_Util::get_parcelpoint( $order );
- $status = Order_Util::get_status( $order );
- $shipping_methods = $order->get_shipping_methods();
- $shipping_method = ! empty( $shipping_methods ) ? array_shift( $shipping_methods ) : null;
- $result[] = array(
- 'internalReference' => '' . Order_Util::get_id( $order ),
- 'reference' => '' . Order_Util::get_order_number( $order ),
- 'status' => array(
- 'key' => $status,
- 'translations' => array(
- $current_language => isset( $statuses[ $status ] ) ? $statuses[ $status ] : $status,
- ),
- ),
- 'shippingMethod' => array(
- 'key' => Order_Item_Shipping_Util::get_method_id( $shipping_method ),
- 'translations' => array(
- $current_language => Order_Item_Shipping_Util::get_name( $shipping_method ),
- ),
- ),
- 'shippingAmount' => Order_Util::get_shipping_total( $order ),
- 'creationDate' => Order_Util::get_date_created( $order ),
- 'orderAmount' => Order_Util::get_total( $order ),
- 'recipient' => $recipient,
- 'products' => $products,
- 'parcelPoint' => null === $parcelpoint ? null : array(
- 'code' => $parcelpoint->code,
- 'network' => $parcelpoint->network,
- ),
- );
- }
- return array( 'orders' => $result );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement