I'm altering different emails from my hook_mail_alter(&$message)
function. But for some reason altering the email sent by commerce invoice module is not working. I'm trying to do it like:
switch($message['id']){
case 'invoice_confirmation':
$message['subject'] = 'Some other title';
break;
I found the code that sends that email in invoice module:
public function send(InvoiceInterface $invoice, $to = NULL, $bcc = NULL) {
$to = isset($to) ? $to : $invoice->getEmail();
if (!$to) {
// The email should not be empty.
return FALSE;
}
$subject = $this->t('Invoice #@number', ['@number' => $invoice->getInvoiceNumber()]);
$body = [
'#theme' => 'commerce_invoice_confirmation',
'#invoice_entity' => $invoice,
'#totals' => $this->invoiceTotalSummary->buildTotals($invoice),
];
if ($billing_profile = $invoice->getBillingProfile()) {
$body['#billing_information'] = $this->profileViewBuilder->view($billing_profile);
}
$params = [
'id' => 'invoice_confirmation',
'from' => $invoice->getStore()->getEmail(),
'bcc' => $bcc,
'invoice' => $invoice,
];
$customer = $invoice->getCustomer();
if ($customer->isAuthenticated()) {
$params['langcode'] = $customer->getPreferredLangcode();
}
$file = $this->invoiceFileManager->getInvoiceFile($invoice);
$attachment = [
'filepath' => $file->getFileUri(),
'filename' => $file->getFilename(),
'filemime' => $file->getMimeType(),
];
$params['attachments'][] = $attachment;
return $this->mailHandler->sendMail($to, $subject, $body, $params);
}
}
and there I saw that id should be 'invoice_confirmation'
, but like my hook function is never reached when this email is sent?! How to alter this email title?