id = self::ID; $this->title = __( 'High-value order', 'admin-powerups-for-woocommerce' ); $this->description = __( 'Sent once when an order over your High-value orders amount is paid. Recipients are set in Admin Powerups.', 'admin-powerups-for-woocommerce' ); $this->email_group = 'orders'; $this->template_html = 'emails/admin-new-order.php'; $this->template_plain = 'emails/plain/admin-new-order.php'; $this->placeholders = array( '{order_date}' => '', '{order_number}' => '', '{order_total}' => '', ); parent::__construct(); $this->customer_email = false; } /** * {@inheritDoc} */ public function get_default_subject() { return __( '[{site_title}]: High-value order #{order_number} ({order_total})', 'admin-powerups-for-woocommerce' ); } /** * {@inheritDoc} */ public function get_default_heading() { return __( 'High-value order: #{order_number}', 'admin-powerups-for-woocommerce' ); } /** * {@inheritDoc} */ public function get_default_additional_content() { return __( 'This order is over your high-value amount. You may want to check it before shipping.', 'admin-powerups-for-woocommerce' ); } /** * {@inheritDoc} Recipients live in the power-up's settings, not here. * * @return void */ public function init_form_fields() { parent::init_form_fields(); unset( $this->form_fields['recipient'] ); } /** * {@inheritDoc} */ public function get_recipient() { if ( null === $this->apwc_recipients ) { $this->apwc_recipients = is_callable( $this->apwc_recipients_source ) ? (string) call_user_func( $this->apwc_recipients_source ) : ''; } $this->recipient = '' !== trim( $this->apwc_recipients ) ? $this->apwc_recipients : (string) get_option( 'admin_email' ); return parent::get_recipient(); } /** * Send for an order. * * @since 1.0.0 * @param WC_Order|int $order Order or ID. * @param string|mixed $recipients Comma-separated recipients (empty = site admin email; anything else = the power-up's). * @return bool Sent. */ public function trigger( $order, $recipients = null ) { $order = is_numeric( $order ) ? wc_get_order( (int) $order ) : $order; if ( ! $order instanceof WC_Order ) { return false; } $this->setup_locale(); $this->object = $order; if ( is_string( $recipients ) ) { // Resend passes ( $order_id, $order ): keep the power-up's recipients. $this->apwc_recipients = $recipients; } $this->placeholders['{order_date}'] = wc_format_datetime( $order->get_date_created() ); $this->placeholders['{order_number}'] = $order->get_order_number(); $this->placeholders['{order_total}'] = wp_strip_all_tags( wc_price( $order->get_total(), array( 'currency' => $order->get_currency() ) ) ); $sent = $this->is_enabled() && $this->get_recipient() ? $this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() ) : false; $this->restore_locale(); return (bool) $sent; } /** * {@inheritDoc} */ public function get_content_html() { return wc_get_template_html( $this->template_html, array( 'order' => $this->object, 'email_heading' => $this->get_heading(), 'additional_content' => $this->get_additional_content(), 'sent_to_admin' => true, 'plain_text' => false, 'email' => $this, ) ); } /** * {@inheritDoc} */ public function get_content_plain() { return wc_get_template_html( $this->template_plain, array( 'order' => $this->object, 'email_heading' => $this->get_heading(), 'additional_content' => $this->get_additional_content(), 'sent_to_admin' => true, 'plain_text' => true, 'email' => $this, ) ); } }