WC_REST_Network_Orders_V2_Controller::network_orders()
Get a collection of orders from the requested blog id
Method of the class: WC_REST_Network_Orders_V2_Controller{}
No Hooks.
Return
WP_REST_Response
.
Usage
$WC_REST_Network_Orders_V2_Controller = new WC_REST_Network_Orders_V2_Controller(); $WC_REST_Network_Orders_V2_Controller->network_orders( $request );
- $request(WP_REST_Request) (required)
- Full details about the request.
WC_REST_Network_Orders_V2_Controller::network_orders() WC REST Network Orders V2 Controller::network orders code WC 9.3.1
public function network_orders( $request ) { $blog_id = $request->get_param( 'blog_id' ); $blog_id = ! empty( $blog_id ) ? $blog_id : get_current_blog_id(); $active_plugins = get_blog_option( $blog_id, 'active_plugins', array() ); $network_active_plugins = array_keys( get_site_option( 'active_sitewide_plugins', array() ) ); $plugins = array_merge( $active_plugins, $network_active_plugins ); $wc_active = false; foreach ( $plugins as $plugin ) { if ( substr_compare( $plugin, '/woocommerce.php', strlen( $plugin ) - strlen( '/woocommerce.php' ), strlen( '/woocommerce.php' ) ) === 0 ) { $wc_active = true; } } // If WooCommerce not active for site, return an empty response. if ( ! $wc_active ) { $response = rest_ensure_response( array() ); return $response; } switch_to_blog( $blog_id ); add_filter( 'woocommerce_rest_orders_prepare_object_query', array( $this, 'network_orders_filter_args' ) ); $items = $this->get_items( $request ); remove_filter( 'woocommerce_rest_orders_prepare_object_query', array( $this, 'network_orders_filter_args' ) ); foreach ( $items->data as &$current_order ) { $order = wc_get_order( $current_order['id'] ); $current_order['blog'] = get_blog_details( get_current_blog_id() ); $current_order['edit_url'] = get_admin_url( $blog_id, 'post.php?post=' . absint( $order->get_id() ) . '&action=edit' ); /* translators: 1: first name 2: last name */ $current_order['customer'] = trim( sprintf( _x( '%1$s %2$s', 'full name', 'woocommerce' ), $order->get_billing_first_name(), $order->get_billing_last_name() ) ); $current_order['status_name'] = wc_get_order_status_name( $order->get_status() ); $current_order['formatted_total'] = $order->get_formatted_order_total(); } restore_current_blog(); return $items; }