Automattic\WooCommerce\Admin\Features\Fulfillments
FulfillmentsManager::update_fulfillment_status_after_refund_deleted
Update fulfillment status after a refund is deleted.
This method updates the fulfillment status after a refund is deleted to ensure that the fulfillment status and items are correctly adjusted based on the refund deletion.
Method of the class: FulfillmentsManager{}
No Hooks.
Returns
null. Nothing (null).
Usage
$FulfillmentsManager = new FulfillmentsManager(); $FulfillmentsManager->update_fulfillment_status_after_refund_deleted( $refund_id ): void;
- $refund_id(int) (required)
- The ID of the refund being deleted.
FulfillmentsManager::update_fulfillment_status_after_refund_deleted() FulfillmentsManager::update fulfillment status after refund deleted code WC 10.9.4
public function update_fulfillment_status_after_refund_deleted( int $refund_id ): void {
$refund = wc_get_order( $refund_id );
if ( ! $refund instanceof \WC_Order ) {
return; // If the refund is not a valid order, do nothing.
}
$order_id = $refund->get_parent_id();
if ( ! $order_id ) {
return; // If the refund does not have a parent order, do nothing.
}
$order = wc_get_order( $order_id );
if ( ! $order instanceof \WC_Order ) {
return; // If the order is not valid, do nothing.
}
try {
/**
* Fulfillments data store.
*
* @var \Automattic\WooCommerce\Admin\Features\Fulfillments\DataStore\FulfillmentsDataStore $fulfillments_data_store
*/
$fulfillments_data_store = \WC_Data_Store::load( 'order-fulfillment' );
$fulfillments = $fulfillments_data_store->read_fulfillments( \WC_Order::class, (string) $order_id );
} catch ( \Throwable $e ) {
wc_get_logger()->error(
sprintf( 'Failed to load fulfillments for order %d: %s', $order_id, $e->getMessage() ),
array( 'source' => 'fulfillments' )
);
return;
}
$this->update_fulfillment_status( $order, $fulfillments );
}