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.
Changelog
| Since 10.1.0 | Introduced. |
| Since 10.8.0 | Date fields are returned as ISO 8601 UTC with 'Z' suffix. |
OrderFulfillmentsRestController::get_fulfillments() OrderFulfillmentsRestController::get fulfillments code WC 10.9.4
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(
fn( $fulfillment ) => $this->prepare_fulfillment_response_data( $fulfillment->get_raw_data() ),
$fulfillments
),
WP_Http::OK
);
}