Automattic\WooCommerce\Internal\Fulfillments

FulfillmentsRenderer::maybe_read_fulfillmentsprivateWC 1.0

Fetches the fulfillments for the given order, caching them to avoid multiple fetches.

Method of the class: FulfillmentsRenderer{}

No Hooks.

Returns

Array. The fulfillments for the order.

Usage

// private - for code of main (parent) class only
$result = $this->maybe_read_fulfillments( $order ): array;
$order(WC_Order) (required)
The order object.

FulfillmentsRenderer::maybe_read_fulfillments() code WC 10.3.3

private function maybe_read_fulfillments( WC_Order $order ): array {
	// Check if we've already fetched the fulfillments for this order.
	if ( isset( $this->fulfillments_cache[ $order->get_id() ] ) ) {
		return $this->fulfillments_cache[ $order->get_id() ];
	}

	// If not, fetch them and cache them.
	$data_store                                   = wc_get_container()->get( FulfillmentsDataStore::class );
	$fulfillments                                 = $data_store->read_fulfillments( WC_Order::class, '' . $order->get_id() );
	$this->fulfillments_cache[ $order->get_id() ] = $fulfillments;

	return $fulfillments;
}