Example #1
0
<div id="invoice_page" class="wpi_invoice_form wpi_payment_form clearfix">
  <div class="wpi_left_col">
    <h3 class="wpi_greeting"><?php 
echo sprintf(__('Welcome, %s!', WPI), recipients_name(array('return' => true)));
?>
</h3>

    <div class="invoice_description">
      <div class="invoice_top_message">
        <?php 
if (is_quote()) {
    ?>
          <p><?php 
    echo sprintf(__('We have sent you a quote in the amount of %s.', WPI), balance_due(array('return' => true)));
    ?>
</p>
        <?php 
}
?>

        <?php 
if (!is_quote()) {
    ?>
          <p><?php 
    echo sprintf(__('We have sent you invoice %1s with a balance of %2s.', WPI), invoice_id(array('return' => true)), balance_due(array('return' => true)));
    ?>
</p>
        <?php 
}
?>
    /**
     * Returns notification email based on pased values
     * 
     * @global object $wpdb
     * @global array $wpi_settings 
     */
    function get_notification_email() {
      global $wpdb, $wpi_settings, $invoice;

      require_once WPI_Path.'/core/wpi_template_functions.php';
      
      $template_id = intval($_REQUEST['template_id']);
      $invoice_id = intval($_REQUEST['wpi_invoiceid']);

      $invoice = get_invoice(wpi_invoice_id_to_post_id($invoice_id));
      $currency_symbol = (!empty($wpi_settings['currency']['symbol'][$invoice['default_currency_code']]) ? $wpi_settings['currency']['symbol'][$invoice['default_currency_code']] : "$");
      $invoice_id = (!empty($invoice['meta']['custom_id']) ? $invoice['meta']['custom_id'] : $invoice['invoice_id']);

      //** Get creator user data */
      $creator = get_userdata( $invoice['post_author'] );
      
      //** Due Date */
      $due_date = get_due_date( $invoice );
      $due_date = $due_date ? $due_date : __('Due date is not set', WPI);
      
      //** Load Templates */
      $template_array = apply_filters('wpi_email_templates', $wpi_settings['notification']);

      $ary['NotificationContent'] = $template_array[$template_id]['content'];
      
      //**
      // Tags which can be used in Content of notification email 
      //*/

      //** Invoice ID */
      $ary['NotificationContent'] = str_replace("%invoice_id%", $invoice_id, $ary['NotificationContent']);

      //** Format description */
      $desc = (!empty($invoice['post_content']) ? strip_tags( $invoice['post_content'] ) : __("No description given.", WPI));
      $ary['NotificationContent'] = str_replace("%description%", $desc, $ary['NotificationContent']);

      //** Recipient name */
      $ary['NotificationContent'] = str_replace("%recipient%", recipients_name(array('return'=>true)), $ary['NotificationContent']);

      //** Invoice link */
      $ary['NotificationContent'] = str_replace("%link%", get_invoice_permalink($invoice['invoice_id']), $ary['NotificationContent']);

      //** Invoice balance */
      $ary['NotificationContent'] = str_replace("%amount%", $currency_symbol . wp_invoice_currency_format($invoice['net']), $ary['NotificationContent']);

      //** Invoice subject/title */
      $ary['NotificationContent'] = str_replace("%subject%", $invoice['post_title'], $ary['NotificationContent']);

      //** Business name according to business settings */
      $ary['NotificationContent'] = str_replace("%business_name%", $wpi_settings['business_name'], $ary['NotificationContent']);

      //** Business email according to business settings */
      $ary['NotificationContent'] = str_replace("%business_email%", $wpi_settings['email_address'], $ary['NotificationContent']);

      //** Invoice creator name */
      $ary['NotificationContent'] = str_replace("%creator_name%", $creator->display_name, $ary['NotificationContent']);

      //** Invoice creator email */
      $ary['NotificationContent'] = str_replace("%creator_email%", $creator->user_email, $ary['NotificationContent']);

      //** Invoice Due Date */ 
      $ary['NotificationContent'] = str_replace("%due_date%", $due_date, $ary['NotificationContent']);

      //** @todo: Recurring */
      $ary['NotificationContent'] = str_replace("%recurring%", '', $ary['NotificationContent']);

      $ary['NotificationSubject'] = $template_array[$template_id]['subject'];

      //**
      // Tags which can be used in Subject of notification email 
      //*/

      //** Invoice ID */
      $ary['NotificationSubject'] = str_replace("%invoice_id%",$invoice_id,$ary['NotificationSubject']);

      //** Recipients name */
      $ary['NotificationSubject'] = str_replace("%recipient%",$invoice['user_data']['display_name'],$ary['NotificationSubject']);

      //** Invoice balance */
      $ary['NotificationSubject'] = str_replace("%amount%",$invoice['net'],$ary['NotificationSubject']);

      //** Invoice subject/title */
      $ary['NotificationSubject'] = str_replace("%subject%",$invoice['post_title'],$ary['NotificationSubject']);

      $aryJson = array();
      //** Filter data before using. korotkov@ud */
      $aryJson['wpi_content'] = apply_filters('wpi_notification_content', $ary['NotificationContent'], $invoice);
      $aryJson['wpi_subject'] = apply_filters('wpi_notification_subject', $ary['NotificationSubject'], $invoice);

      die(json_encode($aryJson));
    }