Modify a booking object before it is saved

Use the woocommerce_bookings_import_pre_save_booking_object filter to change the WC_Booking object after CSV data has been applied but before the importer saves it. This is useful for adding custom metadata or normalizing values that are not part of the default import fields. The snippet below records who imported a new booking and stores a source CSV ID when that value is present.

add_filter(
	'woocommerce_bookings_import_pre_save_booking_object',
	function ( WC_Booking $booking, array $data, bool $updating ): WC_Booking {
		if ( ! $updating ) {
			$booking->update_meta_data( '_imported_by', get_current_user_id() );
		}

		if ( isset( $data['id'] ) ) {
			$booking->update_meta_data( '_source_csv_id', wc_clean( $data['id'] ) );
		}

		return $booking;
	},
	10,
	3
);
Use of your personal data
We and our partners process your personal data (such as browsing data, IP Addresses, cookie information, and other unique identifiers) based on your consent and/or our legitimate interest to optimize our website, marketing activities, and your user experience.