Automattic\WooCommerce\Internal\Fulfillments

OrderFulfillmentsRestController::get_fulfillmentspublicWC 1.0

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() code WC 10.3.3

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 {
		$datastore    = wc_get_container()->get( FulfillmentsDataStore::class );
		$fulfillments = $datastore->read_fulfillments( WC_Order::class, "$order_id" );
	} catch ( \Exception $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
	);
}