Automattic\WooCommerce\Internal\DataStores\Orders

OrdersTableRefundDataStore::delete()publicWC 1.0

Delete a refund order from database.

Method of the class: OrdersTableRefundDataStore{}

No Hooks.

Return

null. Nothing (null).

Usage

$OrdersTableRefundDataStore = new OrdersTableRefundDataStore();
$OrdersTableRefundDataStore->delete( $refund, $args );
$refund(\WC_Order) (required) (passed by reference — &)
Refund object to delete.
$args(array)
Array of args to pass to the delete method.
Default: array()

OrdersTableRefundDataStore::delete() code WC 9.3.3

public function delete( &$refund, $args = array() ) {
	$refund_id = $refund->get_id();
	if ( ! $refund_id ) {
		return;
	}

	$refund_cache_key = WC_Cache_Helper::get_cache_prefix( 'orders' ) . 'refunds' . $refund->get_parent_id();
	wp_cache_delete( $refund_cache_key, 'orders' );

	$this->delete_order_data_from_custom_order_tables( $refund_id );
	$refund->set_id( 0 );

	$orders_table_is_authoritative = $refund->get_data_store()->get_current_class_name() === self::class;

	if ( $orders_table_is_authoritative ) {
		$data_synchronizer = wc_get_container()->get( DataSynchronizer::class );
		if ( $data_synchronizer->data_sync_is_enabled() ) {
			// Delete the associated post, which in turn deletes order items, etc. through {@see WC_Post_Data}.
			// Once we stop creating posts for orders, we should do the cleanup here instead.
			wp_delete_post( $refund_id );
		} else {
			$this->handle_order_deletion_with_sync_disabled( $refund_id );
		}
	}
}