customer specific email attachment

There’s one more argument that you’re not passing, and that includes the WC_Email object ($object is actually an indicator of the object the email is “for” – customer, product, or email).

That last argument passed should allow you to access the methods in WC_Email to figure out the recipient, and therefore the user (which should give you the necessary info to figure out the correct file if you’re attaching it to some user info such as the email or the user ID).

With that said, some of this answer is speculative since I can’t test your specific use case. But if you review the filter in place (such as in includes/emails/class-wc-emails.php), then you should be able to figure out what methods are available.

I’d start by exploring this:

add_filter( 'woocommerce_email_attachments', 'my_attachments', 10, 4 );
function my_attachments( $attachments , $id, $object, $wc_email ) {

    // Start by checking if this is an email to the customer.    
    if ( $wc_email->is_customer_email() ) {

        // Get the recipient
        $recipient = $wc_email->get_recipient();

        /*
         * Assuming the recipient is a single email address, you can use 
         * this to figure out the info to get the attachment (i.e. your 
         * "randomName" value, which presumably has to tie out to the 
         * user somehow). IF that's based on the customer's email address,
         * then you can check $recipient directly. If it's the user ID,
         * then use get_user_by( 'email', $recipient ) to get the user
         * object for the user.
         */

        $attachment_path = get_stylesheet_directory() . '/attachments/' . '<randomName>.pdf'; //How do I make the filename known here
        $attachments[] = $attachment_path;
    
    }
    return $attachments;
}