id = 'Affinite_alert_admin_email'; $this->customer_email = true; $this->title = esc_html__('Stock alert admin info', 'affinite-back-in-stock'); $this->description = esc_html__('Stock alert admin info', 'affinite-back-in-stock'); $this->heading = esc_html__('Stock alert admin info', 'affinite-back-in-stock'); $this->subject = esc_html__('Stock alert admin info from {site_title}', 'affinite-back-in-stock'); // these define the locations of the templates that this email should use, we'll just use the new order template since this email is similar $this->template_html = 'stock-alert-admin-email.php'; $this->template_plain = 'stock-alert-admin-email-plain.php'; $this->templates = array( 'stock-alert-admin-email.php', 'stock-alert-admin-email-plain.php' ); // Call parent constructor to load any other defaults not explicity defined here parent::__construct(); } /** * Determine if the email should actually be sent and setup email merge variables * * @since 0.1 * @param int $order_id */ public function trigger( $product_id ) { $this->product = wc_get_product( $product_id ); $option = get_option( 'affinite_stock_alert' ); if( !empty( $option['admin-email'] ) ){ $recipient = $option['admin-email']; }else{ $recipient = get_option( 'admin_email' ); } if ( ! $this->is_enabled() ) { return; } return $this->send( $recipient, $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() ); } /** * get_content_html function. * * @since 0.1 * @return string */ public function get_content_html() { return wc_get_template_html( $this->template_html, array( 'product' => $this->product, 'email_heading' => $this->get_heading() ) ); } /** * get_content_plain function. * * @since 0.1 * @return string */ public function get_content_plain() { return wc_get_template_html( $this->template_plain, array( 'product' => $this->product, 'email_heading' => $this->get_heading() ) ); } /** * Initialise settings form fields. */ public function init_form_fields() { $this->form_fields = array( 'enabled' => array( 'title' => esc_html__( 'Enable/Disable', 'affinite-back-in-stock' ), 'type' => 'checkbox', 'label' => esc_html__( 'Enable this email notification', 'affinite-back-in-stock' ), 'default' => 'yes', ), 'subject' => array( 'title' => esc_html__( 'Subject', 'affinite-back-in-stock' ), 'type' => 'text', 'desc_tip' => true, /* translators: %s: list of placeholders */ 'description' => sprintf( esc_html__( 'Available placeholders: %s', 'affinite-back-in-stock' ), '{site_title}, {order_date}, {order_number}' ), 'placeholder' => $this->get_default_subject(), 'default' => '', ), 'heading' => array( 'title' => esc_html__( 'Email heading', 'affinite-back-in-stock' ), 'type' => 'text', 'desc_tip' => true, /* translators: %s: list of placeholders */ 'description' => sprintf( esc_html__( 'Available placeholders: %s', 'affinite-back-in-stock' ), '{site_title}, {order_date}, {order_number}' ), 'placeholder' => $this->get_default_heading(), 'default' => '', ), 'email_type' => array( 'title' => esc_html__( 'Email type', 'affinite-back-in-stock' ), 'type' => 'select', 'description' => esc_html__( 'Choose which format of email to send.', 'affinite-back-in-stock' ), 'default' => 'html', 'class' => 'email_type wc-enhanced-select', 'options' => $this->get_email_type_options(), 'desc_tip' => true, ), ); } } // end class