Advertisement
nshelper

Untitled

Feb 6th, 2025
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.66 KB | None | 0 0
  1. public function get_orders() {
  2. $result = array();
  3. $statuses = Order_Util::get_import_status_list();
  4. $current_language = get_locale();
  5. foreach ( wc_get_orders(
  6. array(
  7. 'status' => array_keys( $statuses ),
  8. 'limit' => -1,
  9. )
  10. ) as $order ) {
  11. $recipient = array(
  12. 'firstname' => Misc_Util::not_empty_or_null( Order_Util::get_shipping_first_name( $order ) ),
  13. 'lastname' => Misc_Util::not_empty_or_null( Order_Util::get_shipping_last_name( $order ) ),
  14. 'company' => Misc_Util::not_empty_or_null( Order_Util::get_shipping_company( $order ) ),
  15. 'addressLine1' => Misc_Util::not_empty_or_null( Order_Util::get_shipping_address_1( $order ) ),
  16. 'addressLine2' => Misc_Util::not_empty_or_null( Order_Util::get_shipping_address_2( $order ) ),
  17. 'city' => Misc_Util::not_empty_or_null( Order_Util::get_shipping_city( $order ) ),
  18. 'state' => Misc_Util::not_empty_or_null( Order_Util::get_shipping_state( $order ) ),
  19. 'postcode' => Misc_Util::not_empty_or_null( Order_Util::get_shipping_postcode( $order ) ),
  20. 'country' => Misc_Util::not_empty_or_null( Order_Util::get_shipping_country( $order ) ),
  21. 'phone' => Misc_Util::not_empty_or_null( Order_Util::get_billing_phone( $order ) ),
  22. 'email' => Misc_Util::not_empty_or_null( Order_Util::get_billing_email( $order ) ),
  23. );
  24. $products = array();
  25. foreach ( $order->get_items( 'line_item' ) as $item ) {
  26. do_action( 'woocommerce/cart_loop/start', $item );
  27. $product = array();
  28. $variation_id = $item['variation_id'];
  29. $product_id = ( '0' !== $variation_id && 0 !== $variation_id ) ? $variation_id : $item['product_id'];
  30.  
  31. if ( ! Product_Util::is_product_virtual( $product_id ) ) {
  32. $product['weight'] = false !== Product_Util::get_product_weight( $product_id ) ? (float) Product_Util::get_product_weight( $product_id ) : null;
  33. $product['quantity'] = (int) $item['qty'];
  34. $product['price'] = Product_Util::get_product_price( $product_id );
  35. $product['description'] = array(
  36. $current_language => esc_html( Product_Util::get_product_description( $item ) ),
  37. );
  38. $products[] = $product;
  39. }
  40. do_action( 'woocommerce/cart_loop/end', $item );
  41. }
  42.  
  43. $parcelpoint = Order_Util::get_parcelpoint( $order );
  44. $status = Order_Util::get_status( $order );
  45. $shipping_methods = $order->get_shipping_methods();
  46. $shipping_method = ! empty( $shipping_methods ) ? array_shift( $shipping_methods ) : null;
  47. $result[] = array(
  48. 'internalReference' => '' . Order_Util::get_id( $order ),
  49. 'reference' => '' . Order_Util::get_order_number( $order ),
  50. 'status' => array(
  51. 'key' => $status,
  52. 'translations' => array(
  53. $current_language => isset( $statuses[ $status ] ) ? $statuses[ $status ] : $status,
  54. ),
  55. ),
  56. 'shippingMethod' => array(
  57. 'key' => Order_Item_Shipping_Util::get_method_id( $shipping_method ),
  58. 'translations' => array(
  59. $current_language => Order_Item_Shipping_Util::get_name( $shipping_method ),
  60. ),
  61. ),
  62. 'shippingAmount' => Order_Util::get_shipping_total( $order ),
  63. 'creationDate' => Order_Util::get_date_created( $order ),
  64. 'orderAmount' => Order_Util::get_total( $order ),
  65. 'recipient' => $recipient,
  66. 'products' => $products,
  67. 'parcelPoint' => null === $parcelpoint ? null : array(
  68. 'code' => $parcelpoint->code,
  69. 'network' => $parcelpoint->network,
  70. ),
  71. );
  72. }
  73. return array( 'orders' => $result );
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement