template_base = wc_square()->get_plugin_path() . '/templates/'; // call parent constructor parent::__construct(); // set default recipient $this->recipient = $this->get_option( 'recipient', get_option( 'admin_email' ) ); } /** * Initializes the email settings form fields. * * Extends and overrides parent method. * * @since 2.1.0 */ public function init_form_fields() { // initialize the default fields from parent email object parent::init_form_fields(); $form_fields = $this->form_fields; // set email disabled by default if ( isset( $form_fields['enabled'] ) ) { $form_fields['enabled']['default'] = $this->enabled_default; } // the email has no customizable body or heading via input field unset( $form_fields['body'], $form_fields['heading'] ); // adjust email subject field if ( isset( $form_fields['subject'] ) ) { /* translators: Placeholder: %s - default email subject text */ $form_fields['subject']['description'] = sprintf( __( 'This controls the email subject line. Leave blank to use the default subject: %s', 'woocommerce-square' ), '' . $this->get_default_subject() . '' ); $form_fields['subject']['desc_tip'] = false; $form_fields['subject']['default'] = $this->subject; } if ( ! $this->is_customer_email() ) { // add a recipient field $form_fields = Square_Helper::array_insert_after( $form_fields, isset( $form_fields['enabled'] ) ? 'enabled' : key( $form_fields ), array( 'recipient' => array( 'title' => __( 'Recipient(s)', 'woocommerce-square' ), 'type' => 'text', /* translators: %s default email address */ 'description' => sprintf( __( 'Enter recipients (comma separated) for this email. Defaults to admin email: %s', 'woocommerce-square' ), '' . esc_attr( get_option( 'admin_email' ) ) . '' ), 'placeholder' => get_bloginfo( 'admin_email' ), 'default' => get_bloginfo( 'admin_email' ), ), ) ); } // set the updated fields $this->form_fields = $form_fields; } /** * Gets the default email subject. * * @since 2.1.0 * * @return string */ public function get_default_subject() { return $this->subject; } /** * Gets the email body. * * @since 2.1.0 * * @return string may contain HTML */ protected function get_default_body() { return $this->body; } /** * Determines if the email has valid recipients. * * @since 2.1.0 * * @return bool */ protected function has_recipients() { return ! empty( $this->get_recipient() ); } /** * Gets the arguments that should be passed to an email template. * * @since 2.1.0 * * @param array $args optional associative array with additional arguments * @return array */ protected function get_template_args( $args = array() ) { return array_merge( $args, array( 'email' => $this, 'email_body' => '', 'email_heading' => '', 'additional_content' => '', ) ); } /** * Gets the email HTML content. * * @since 2.0.0 * * @return string HTML */ public function get_content_html() { $args = array( 'plain_text' => false ); return wc_get_template_html( $this->template_html, array_merge( $args, $this->get_template_args( $args ) ) ); } /** * Gets the email plain text content. * * @since 2.0.0 * * @return string plain text */ public function get_content_plain() { $args = array( 'plain_text' => true ); return wc_get_template_html( $this->template_plain, array_merge( $args, $this->get_template_args( $args ) ) ); } }