Automattic\WooCommerce\Admin\Features\Fulfillments
OrderFulfillmentsRestController::get_fulfillments
Get the fulfillments for the order.
Method of the class: OrderFulfillmentsRestController{}
No Hooks.
Returns
WP_REST_Response. The fulfillments for the order, or an error if the request fails.
Usage
$OrderFulfillmentsRestController = new OrderFulfillmentsRestController(); $OrderFulfillmentsRestController->get_fulfillments( $request ): WP_REST_Response;
- $request(WP_REST_Request) (required)
- The request object.
OrderFulfillmentsRestController::get_fulfillments() OrderFulfillmentsRestController::get fulfillments code WC 10.7.0
public function get_fulfillments( WP_REST_Request $request ): WP_REST_Response {
$order_id = (int) $request->get_param( 'order_id' );
$fulfillments = array();
// Fetch fulfillments for the order.
try {
/**
* Fulfillments data store.
*
* @var \Automattic\WooCommerce\Admin\Features\Fulfillments\DataStore\FulfillmentsDataStore $datastore
*/
$datastore = \WC_Data_Store::load( 'order-fulfillment' );
$fulfillments = $datastore->read_fulfillments( WC_Order::class, "$order_id" );
} catch ( \Throwable $e ) {
return $this->prepare_error_response(
$e->getCode(),
$e->getMessage(),
WP_Http::BAD_REQUEST
);
}
// Return the fulfillments.
return new WP_REST_Response(
array_map(
function ( $fulfillment ) {
return $fulfillment->get_raw_data(); },
$fulfillments
),
WP_Http::OK
);
}