Advertisement
Guest User

Untitled

a guest
Apr 26th, 2013
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.90 KB | None | 0 0
  1. <?php
  2.  
  3. if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
  4.  
  5. /**
  6.  * New Order Email
  7.  *
  8.  * An email sent to the admin when a new order is received/paid for.
  9.  *
  10.  * @class       WC_Email_New_Order
  11.  * @version     2.0.0
  12.  * @package     WooCommerce/Classes/Emails
  13.  * @author      WooThemes
  14.  * @extends     WC_Email
  15.  */
  16. class WC_Email_New_Order extends WC_Email {
  17.  
  18.     /**
  19.      * Constructor
  20.      */
  21.     function __construct() {
  22.  
  23.         $this->id               = 'new_order';
  24.         $this->title            = __( 'New order', 'woocommerce' );
  25.         $this->description      = __( 'New order emails are sent when an order is received/paid by a customer.', 'woocommerce' );
  26.  
  27.         $this->heading          = __( 'New customer order', 'woocommerce' );
  28.         $this->subject          = __( '[{blogname}] New customer order ({order_number}) - {order_date}', 'woocommerce' );
  29.  
  30.         $this->template_html    = 'emails/admin-new-order.php';
  31.         $this->template_plain   = 'emails/plain/admin-new-order.php';
  32.  
  33.         // Triggers for this email
  34.         add_action( 'woocommerce_order_status_pending_to_processing_notification', array( $this, 'trigger' ) );
  35.         add_action( 'woocommerce_order_status_pending_to_completed_notification', array( $this, 'trigger' ) );
  36.         add_action( 'woocommerce_order_status_pending_to_on-hold_notification', array( $this, 'trigger' ) );
  37.         add_action( 'woocommerce_order_status_failed_to_processing_notification', array( $this, 'trigger' ) );
  38.         add_action( 'woocommerce_order_status_failed_to_completed_notification', array( $this, 'trigger' ) );
  39.         add_action( 'woocommerce_order_status_failed_to_on-hold_notification', array( $this, 'trigger' ) );
  40.  
  41.         // Call parent constructor
  42.         parent::__construct();
  43.  
  44.         // Other settings
  45.         $this->recipient = $this->get_option( 'recipient' );
  46.  
  47.         if ( ! $this->recipient )
  48.             $this->recipient = get_option( 'admin_email' );
  49.     }
  50.  
  51.     /**
  52.      * trigger function.
  53.      *
  54.      * @access public
  55.      * @return void
  56.      */
  57.     function trigger( $order_id ) {
  58.         global $woocommerce;
  59.  
  60.         if ( $order_id ) {
  61.             $this->object       = new WC_Order( $order_id );
  62.  
  63.             $this->find[] = '{order_date}';
  64.             $this->replace[] = date_i18n( woocommerce_date_format(), strtotime( $this->object->order_date ) );
  65.  
  66.             $this->find[] = '{order_number}';
  67.             $this->replace[] = $this->object->get_order_number();
  68.         }
  69.  
  70.         if ( ! $this->is_enabled() || ! $this->get_recipient() )
  71.             return;
  72.  
  73.         $this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
  74.     }
  75.  
  76.     /**
  77.      * get_content_html function.
  78.      *
  79.      * @access public
  80.      * @return string
  81.      */
  82.     function get_content_html() {
  83.         ob_start();
  84.         woocommerce_get_template( $this->template_html, array(
  85.             'order'         => $this->object,
  86.             'email_heading' => $this->get_heading()
  87.         ) );
  88.         return ob_get_clean();
  89.     }
  90.  
  91.     /**
  92.      * get_content_plain function.
  93.      *
  94.      * @access public
  95.      * @return string
  96.      */
  97.     function get_content_plain() {
  98.         ob_start();
  99.         woocommerce_get_template( $this->template_plain, array(
  100.             'order'         => $this->object,
  101.             'email_heading' => $this->get_heading()
  102.         ) );
  103.         return ob_get_clean();
  104.     }
  105.  
  106.     /**
  107.      * Initialise Settings Form Fields
  108.      *
  109.      * @access public
  110.      * @return void
  111.      */
  112.     function init_form_fields() {
  113.         $this->form_fields = array(
  114.             'enabled' => array(
  115.                 'title'         => __( 'Enable/Disable', 'woocommerce' ),
  116.                 'type'          => 'checkbox',
  117.                 'label'         => __( 'Enable this email notification', 'woocommerce' ),
  118.                 'default'       => 'yes'
  119.             ),
  120.             'recipient' => array(
  121.                 'title'         => __( 'Recipient(s)', 'woocommerce' ),
  122.                 'type'          => 'text',
  123.                 'description'   => sprintf( __( 'Enter recipients (comma separated) for this email. Defaults to <code>%s</code>.', 'woocommerce' ), esc_attr( get_option('admin_email') ) ),
  124.                 'placeholder'   => '',
  125.                 'default'       => ''
  126.             ),
  127.             'subject' => array(
  128.                 'title'         => __( 'Subject', 'woocommerce' ),
  129.                 'type'          => 'text',
  130.                 'description'   => sprintf( __( 'This controls the email subject line. Leave blank to use the default subject: <code>%s</code>.', 'woocommerce' ), $this->subject ),
  131.                 'placeholder'   => '',
  132.                 'default'       => ''
  133.             ),
  134.             'heading' => array(
  135.                 'title'         => __( 'Email Heading', 'woocommerce' ),
  136.                 'type'          => 'text',
  137.                 'description'   => sprintf( __( 'This controls the main heading contained within the email notification. Leave blank to use the default heading: <code>%s</code>.', 'woocommerce' ), $this->heading ),
  138.                 'placeholder'   => '',
  139.                 'default'       => ''
  140.             ),
  141.             'email_type' => array(
  142.                 'title'         => __( 'Email type', 'woocommerce' ),
  143.                 'type'          => 'select',
  144.                 'description'   => __( 'Choose which format of email to send.', 'woocommerce' ),
  145.                 'default'       => 'html',
  146.                 'class'         => 'email_type',
  147.                 'options'       => array(
  148.                     'plain'         => __( 'Plain text', 'woocommerce' ),
  149.                     'html'          => __( 'HTML', 'woocommerce' ),
  150.                     'multipart'     => __( 'Multipart', 'woocommerce' ),
  151.                 )
  152.             )
  153.         );
  154.     }
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement