Automattic\WooCommerce\Internal\Fulfillments

OrderFulfillmentsRestController::get_fulfillmentpublicWC 1.0

Get a specific fulfillment for the order.

Method of the class: OrderFulfillmentsRestController{}

No Hooks.

Returns

WP_REST_Response. The fulfillment for the order, or an error if the request fails.

Usage

$OrderFulfillmentsRestController = new OrderFulfillmentsRestController();
$OrderFulfillmentsRestController->get_fulfillment( $request ): WP_REST_Response;
$request(WP_REST_Request) (required)
The request object.

OrderFulfillmentsRestController::get_fulfillment() code WC 10.3.3

public function get_fulfillment( WP_REST_Request $request ): WP_REST_Response {
	$order_id       = (int) $request->get_param( 'order_id' );
	$fulfillment_id = (int) $request->get_param( 'fulfillment_id' );

	// Fetch the fulfillment for the order.
	try {
		$fulfillment = new Fulfillment( $fulfillment_id );
		$this->validate_fulfillment( $fulfillment, $fulfillment_id, $order_id );
		if ( $fulfillment->get_date_deleted() ) {
			throw new \Exception(
				esc_html__( 'Fulfillment not found.', 'woocommerce' ),
				WP_Http::NOT_FOUND
			);
		}
	} catch ( \Exception $e ) {
		return $this->prepare_error_response(
			$e->getCode(),
			$e->getMessage(),
			WP_Http::BAD_REQUEST
		);
	}

	return new WP_REST_Response(
		$fulfillment->get_raw_data(),
		WP_Http::OK
	);
}