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