Automattic\WooCommerce\Internal\Fulfillments

FulfillmentsManager::update_fulfillment_status_after_refund_deletedpublicWC 1.0

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() code WC 10.3.3

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.
	}

	$fulfillments_data_store = wc_get_container()->get( FulfillmentsDataStore::class );
	$fulfillments            = $fulfillments_data_store->read_fulfillments( \WC_Order::class, (string) $order_id );

	$this->update_fulfillment_status( $order, $fulfillments );
}