I want to add two pdf files to the new user registration e-mail of WooCommerce.
Because I have two specific user roles customer
and seller
.
I want to send all new sellers two pdf files from paths $path1
and $path3
and all new customers two pdf files from paths $path2
and $path3
.
I tried this in my functions.php
function attach_to_email ( $attachments, $userrole ) {
$root = ABSPATH;
$path1 = $root . '/media/AGB H.pdf';
$path2 = $root . '/media/AGB K.pdf';
$path3 = $root . '/media/W.pdf';
if ( $userrole === 'seller' ) {
$attachments[] = $path1;
$attachments[] = $path3;
} else {
$attachments[] = $path2;
$attachments[] = $path3;
}
return $attachments;
}
add_filter( 'woocommerce_email_attachments', 'attach_to_email', 10, 2 );
In the e-mail template for sellers I call:
do_action( 'woocommerce_email_attachments', null, 'seller' );
But in the function, I always enter the else part and not the if-part. In addition, all e-mails are attached with the else-files now, not only the registration e-mails. Any ideas?