/**
 * Sends required notifications korotkov@UD
 * @global array $wpi_settings
 * @param array $invoice
 * @author korotkov@UD
 */
function send_notification( $invoice ) {
  global $wpi_settings;

  if ( (!empty($wpi_settings['send_thank_you_email']) && $wpi_settings['send_thank_you_email'] == 'true') ||
       (!empty($wpi_settings['cc_thank_you_email']) && $wpi_settings['cc_thank_you_email'] == 'true') ||
       (!empty($wpi_settings['send_invoice_creator_email']) && $wpi_settings['send_invoice_creator_email'] == 'true' ) ) {

    $paid_invoice = new WPI_Invoice();
    $paid_invoice->load_invoice("id={$invoice['invoice_id']}");

    /** Email client */
    if (!empty($wpi_settings['send_thank_you_email']) && $wpi_settings['send_thank_you_email'] == 'true') {
      wp_invoice_send_email_receipt($paid_invoice->data);
    }

    /** Email site admin */
    if (!empty($wpi_settings['cc_thank_you_email']) && $wpi_settings['cc_thank_you_email'] == 'true') {
      wp_invoice_send_me_notification($paid_invoice->data);
    }

    /** Email invoice creator */
    if ( !empty( $wpi_settings['send_invoice_creator_email'] ) && $wpi_settings['send_invoice_creator_email'] == 'true' ){
      wp_invoice_send_creator_notification($paid_invoice->data);
    }

  }

}
Beispiel #2
0
/**
 * Sends required notifications
 *
 * @global array $wpi_settings
 *
 * @param array $invoice
 *
 * @author korotkov@UD
 * @refactoring odokienko@UD
 */
function send_notification($invoice)
{
    global $wpi_settings;
    if (!empty($wpi_settings['send_thank_you_email']) && $wpi_settings['send_thank_you_email'] == 'true' || !empty($wpi_settings['cc_thank_you_email']) && $wpi_settings['cc_thank_you_email'] == 'true' || !empty($wpi_settings['send_invoice_creator_email']) && $wpi_settings['send_invoice_creator_email'] == 'true') {
        $paid_invoice = new WPI_Invoice();
        $paid_invoice->load_invoice("id={$invoice['invoice_id']}");
        $invoice = $paid_invoice->data;
        $notification_data['invoice_id'] = !empty($invoice['custom_id']) ? $invoice['custom_id'] : $invoice['invoice_id'];
        $notification_data['invoice_title'] = $invoice['post_title'];
        $notification_data['from'] = stripslashes(get_option('admin_email'));
        $notification_data['permalink'] = get_invoice_permalink($invoice['invoice_id']);
        $notification_data['business_name'] = $wpi_settings['business_name'];
        $notification_data['site'] = stripslashes($wpi_settings['business_name']);
        $notification_data['user_email'] = $invoice['user_data']['user_email'];
        $notification_data['user_name'] = wpi_get_user_display_name($invoice);
        $notification_data['user_id'] = $invoice['user_data']['ID'];
        $admin = get_user_by('email', get_option('admin_email'));
        $notification_data['admin_email'] = stripslashes($admin->user_email);
        $notification_data['admin_id'] = $admin->ID;
        $notification_data['admin_name'] = stripslashes($admin->display_name);
        $creator = get_userdata($invoice['post_author']);
        $notification_data['creator_email'] = stripslashes($creator->user_email);
        $notification_data['creator_name'] = stripslashes($creator->display_name);
        $notification_data['creator_id'] = $creator->ID;
        $notification_data['total'] = $invoice['subtotal'] - $invoice['total_discount'] + $invoice['total_tax'];
        $notification_data['default_currency_code'] = $invoice['default_currency_code'];
        $notification_data['total_payments'] = $invoice['total_payments'];
        //** If we are going to change our Mail From */
        if (!empty($wpi_settings['change_mail_from']) && $wpi_settings['change_mail_from'] == 'true') {
            add_filter('wp_mail_from', array('WPI_Functions', 'notification_mail_from'));
            add_filter('wp_mail_from_name', array('WPI_Functions', 'notification_mail_from_name'));
        }
        /** Email client */
        if (!empty($wpi_settings['send_thank_you_email']) && $wpi_settings['send_thank_you_email'] == 'true') {
            wp_invoice_send_email_receipt($invoice, $notification_data);
        }
        /** Email site admin */
        if (!empty($wpi_settings['cc_thank_you_email']) && $wpi_settings['cc_thank_you_email'] == 'true') {
            wp_invoice_send_me_notification($invoice, $notification_data);
        }
        /** Email invoice creator */
        if (!empty($wpi_settings['send_invoice_creator_email']) && $wpi_settings['send_invoice_creator_email'] == 'true') {
            wp_invoice_send_creator_notification($invoice, $notification_data);
        }
        remove_filter('wp_mail_from', array('WPI_Functions', 'notification_mail_from'));
        remove_filter('wp_mail_from_name', array('WPI_Functions', 'notification_mail_from_name'));
    }
}