Automattic\WooCommerce\Admin\Features\Fulfillments
FulfillmentsRenderer::maybe_read_fulfillments
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() FulfillmentsRenderer::maybe read fulfillments code WC 10.7.0
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.
try {
/**
* Fulfillments data store.
*
* @var \Automattic\WooCommerce\Admin\Features\Fulfillments\DataStore\FulfillmentsDataStore $data_store
*/
$data_store = \WC_Data_Store::load( 'order-fulfillment' );
$fulfillments = $data_store->read_fulfillments( WC_Order::class, '' . $order->get_id() );
} catch ( \Throwable $e ) {
wc_get_logger()->error(
sprintf( 'Failed to load fulfillments for order %d: %s', $order->get_id(), $e->getMessage() ),
array( 'source' => 'fulfillments' )
);
$fulfillments = array();
}
$this->fulfillments_cache[ $order->get_id() ] = $fulfillments;
return $fulfillments;
}