WC_REST_Fulfillments_V4_Controller::create_fulfillmentpublicWC 1.0

Create a fulfillment for a specific order.

Method of the class: WC_REST_Fulfillments_V4_Controller{}

No Hooks.

Returns

WP_REST_Response.

Usage

$WC_REST_Fulfillments_V4_Controller = new WC_REST_Fulfillments_V4_Controller();
$WC_REST_Fulfillments_V4_Controller->create_fulfillment( $request ): WP_REST_Response;
$request(WP_REST_Request) (required)
Full details about the request.

WC_REST_Fulfillments_V4_Controller::create_fulfillment() code WC 10.3.6

public function create_fulfillment( WP_REST_Request $request ): WP_REST_Response {
	$params    = $request->get_json_params();
	$entity_id = $params['entity_id'] ?? null;

	// Validate the entity ID.
	if ( ! $entity_id ) {
		return $this->prepare_error_response(
			'woocommerce_rest_entity_id_required',
			__( 'The entity ID is required.', 'woocommerce' ),
			array( 'status' => esc_attr( WP_Http::BAD_REQUEST ) )
		);
	}
	$order = wc_get_order( (int) $entity_id );
	if ( ! $order ) {
		return $this->prepare_error_response(
			'woocommerce_rest_order_invalid_id',
			__( 'Invalid order ID.', 'woocommerce' ),
			array( 'status' => esc_attr( WP_Http::NOT_FOUND ) )
		);
	}

	$request->set_param( 'order_id', $entity_id );
	return $this->order_fulfillments_controller->create_fulfillment( $request );
}