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
);