WC_Email_New_Order

New Order Email.

Defined (1)

The class is defined in the following location(s).

/includes/emails/class-wc-email-new-order.php  
  1. class WC_Email_New_Order extends WC_Email { 
  2.  
  3. /** 
  4. * Constructor. 
  5. */ 
  6. public function __construct() { 
  7. $this->id = 'new_order'; 
  8. $this->title = __( 'New order', 'woocommerce' ); 
  9. $this->description = __( 'New order emails are sent to chosen recipient(s) when a new order is received.', 'woocommerce' ); 
  10. $this->heading = __( 'New customer order', 'woocommerce' ); 
  11. $this->subject = __( '[{site_title}] New customer order ({order_number}) - {order_date}', 'woocommerce' ); 
  12. $this->template_html = 'emails/admin-new-order.php'; 
  13. $this->template_plain = 'emails/plain/admin-new-order.php'; 
  14.  
  15. // Triggers for this email 
  16. add_action( 'woocommerce_order_status_pending_to_processing_notification', array( $this, 'trigger' ), 10, 2 ); 
  17. add_action( 'woocommerce_order_status_pending_to_completed_notification', array( $this, 'trigger' ), 10, 2 ); 
  18. add_action( 'woocommerce_order_status_pending_to_on-hold_notification', array( $this, 'trigger' ), 10, 2 ); 
  19. add_action( 'woocommerce_order_status_failed_to_processing_notification', array( $this, 'trigger' ), 10, 2 ); 
  20. add_action( 'woocommerce_order_status_failed_to_completed_notification', array( $this, 'trigger' ), 10, 2 ); 
  21. add_action( 'woocommerce_order_status_failed_to_on-hold_notification', array( $this, 'trigger' ), 10, 2 ); 
  22.  
  23. // Call parent constructor 
  24. parent::__construct(); 
  25.  
  26. // Other settings 
  27. $this->recipient = $this->get_option( 'recipient', get_option( 'admin_email' ) ); 
  28.  
  29. /** 
  30. * Trigger the sending of this email. 
  31. * @param int $order_id The order ID. 
  32. * @param WC_Order $order Order object. 
  33. */ 
  34. public function trigger( $order_id, $order = false ) { 
  35. if ( $order_id && ! is_a( $order, 'WC_Order' ) ) { 
  36. $order = wc_get_order( $order_id ); 
  37.  
  38. if ( is_a( $order, 'WC_Order' ) ) { 
  39. $this->object = $order; 
  40. $this->find['order-date'] = '{order_date}'; 
  41. $this->find['order-number'] = '{order_number}'; 
  42. $this->replace['order-date'] = wc_format_datetime( $this->object->get_date_created() ); 
  43. $this->replace['order-number'] = $this->object->get_order_number(); 
  44.  
  45. if ( ! $this->is_enabled() || ! $this->get_recipient() ) { 
  46. return; 
  47.  
  48. $this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() ); 
  49.  
  50. /** 
  51. * Get content html. 
  52. * @access public 
  53. * @return string 
  54. */ 
  55. public function get_content_html() { 
  56. return wc_get_template_html( $this->template_html, array( 
  57. 'order' => $this->object,  
  58. 'email_heading' => $this->get_heading(),  
  59. 'sent_to_admin' => true,  
  60. 'plain_text' => false,  
  61. 'email' => $this,  
  62. ) ); 
  63.  
  64. /** 
  65. * Get content plain. 
  66. * @access public 
  67. * @return string 
  68. */ 
  69. public function get_content_plain() { 
  70. return wc_get_template_html( $this->template_plain, array( 
  71. 'order' => $this->object,  
  72. 'email_heading' => $this->get_heading(),  
  73. 'sent_to_admin' => true,  
  74. 'plain_text' => true,  
  75. 'email' => $this,  
  76. ) ); 
  77.  
  78. /** 
  79. * Initialise settings form fields. 
  80. */ 
  81. public function init_form_fields() { 
  82. $this->form_fields = array( 
  83. 'enabled' => array( 
  84. 'title' => __( 'Enable/Disable', 'woocommerce' ),  
  85. 'type' => 'checkbox',  
  86. 'label' => __( 'Enable this email notification', 'woocommerce' ),  
  87. 'default' => 'yes',  
  88. ),  
  89. 'recipient' => array( 
  90. 'title' => __( 'Recipient(s)', 'woocommerce' ),  
  91. 'type' => 'text',  
  92. 'description' => sprintf( __( 'Enter recipients (comma separated) for this email. Defaults to %s.', 'woocommerce' ), '<code>' . esc_attr( get_option( 'admin_email' ) ) . '</code>' ),  
  93. 'placeholder' => '',  
  94. 'default' => '',  
  95. 'desc_tip' => true,  
  96. ),  
  97. 'subject' => array( 
  98. 'title' => __( 'Subject', 'woocommerce' ),  
  99. 'type' => 'text',  
  100. 'description' => sprintf( __( 'This controls the email subject line. Leave blank to use the default subject: %s.', 'woocommerce' ), '<code>' . $this->subject . '</code>' ),  
  101. 'placeholder' => '',  
  102. 'default' => '',  
  103. 'desc_tip' => true,  
  104. ),  
  105. 'heading' => array( 
  106. 'title' => __( 'Email heading', 'woocommerce' ),  
  107. 'type' => 'text',  
  108. 'description' => sprintf( __( 'This controls the main heading contained within the email notification. Leave blank to use the default heading: %s.', 'woocommerce' ), '<code>' . $this->heading . '</code>' ),  
  109. 'placeholder' => '',  
  110. 'default' => '',  
  111. 'desc_tip' => true,  
  112. ),  
  113. 'email_type' => array( 
  114. 'title' => __( 'Email type', 'woocommerce' ),  
  115. 'type' => 'select',  
  116. 'description' => __( 'Choose which format of email to send.', 'woocommerce' ),  
  117. 'default' => 'html',  
  118. 'class' => 'email_type wc-enhanced-select',  
  119. 'options' => $this->get_email_type_options(),  
  120. 'desc_tip' => true,  
  121. ),  
  122. );