You are here

function uc_notify_checkout in Ubercart 5

Send new order confirmation e-mail to customer and/or administrator.

1 call to uc_notify_checkout()
uc_notify_order in uc_notify/uc_notify.module
Implementation of hook_order().

File

uc_notify/uc_notify.module, line 312
Handles configuration and execution of email notifications.

Code

function uc_notify_checkout($order) {
  if (variable_get('uc_notify_cust_checkout_enabled', TRUE)) {
    if (($template = variable_get('uc_notify_cust_checkout_template', 'customer')) == '0') {
      $body = variable_get('uc_notify_cust_checkout_custom', '');
      $body = check_markup($body, variable_get('uc_notify_cust_checkout_format', 3), FALSE);
    }
    else {
      $body = uc_order_load_invoice($order, 'checkout-mail', $template);
    }
    $body = token_replace_multiple($body, array(
      'global' => NULL,
      'order' => $order,
    ));
    $subject = variable_get('uc_notify_cust_checkout_subject', t('Your Order at [store-name]'));
    $subject = token_replace_multiple($subject, array(
      'global' => NULL,
      'order' => $order,
    ));
    $email_to = $order->primary_email;
    $headers = uc_notify_headers();
    $sent = drupal_mail('checkout', $email_to, $subject, $body, uc_store_email_from(), $headers);
    if ($sent) {
      $changes[] = t('Checkout message sent to @email.', array(
        '@email' => $order->primary_email,
      ));
    }
    else {
      $changes[] = t('Checkout e-mail notification to @email failed.', array(
        '@email' => $order->primary_email,
      ));
    }
    uc_order_log_changes($order->order_id, $changes);
  }

  // Send administrator e-mails.
  if (variable_get('uc_notify_admin_checkout_enabled', FALSE)) {
    if (($template = variable_get('uc_notify_admin_checkout_template', 'admin')) == '0') {
      $body = variable_get('uc_notify_admin_checkout_custom', '');
      $body = check_markup($body, variable_get('uc_notify_admin_checkout_format', 3), FALSE);
    }
    else {
      $body = uc_order_load_invoice($order, 'admin-mail', $template);
    }
    $body = token_replace_multiple($body, array(
      'global' => NULL,
      'order' => $order,
    ));
    $subject = variable_get('uc_notify_admin_checkout_subject', t('New Order at [store-name]'));
    $subject = token_replace_multiple($subject, array(
      'global' => NULL,
      'order' => $order,
    ));
    $email_from = uc_store_email_from();
    $headers = uc_notify_headers();
    $emails = preg_split('/\\s+/', variable_get('uc_notify_admin_checkout_emails', variable_get('uc_store_email', '')));
    foreach ($emails as $email_to) {
      if (!empty($email_to) && valid_email_address($email_to)) {
        drupal_mail('admin_checkout', $email_to, $subject, $body, $email_from, $headers);
      }
    }
  }
}