You are here

function commerce_store_mail_alter in Commerce Core 8.2

Implements hook_mail_alter().

Sets the default "from" address to the current store email.

File

modules/store/commerce_store.module, line 16
Defines the Store entity and associated features.

Code

function commerce_store_mail_alter(&$message) {
  if (substr($message['id'], 0, 9) == 'commerce_' && empty($message['params']['from'])) {

    /** @var \Drupal\commerce_store\CurrentStoreInterface $current_store */
    $current_store = \Drupal::service('commerce_store.current_store');
    $current_store = $current_store
      ->getStore();
    if ($current_store) {
      $message['from'] = $current_store
        ->getEmail();
    }
  }
}