douchun5969 2016-07-10 22:03
浏览 83

添加自定义woocommerce电子邮件以订购批量操作

I've added a custom woocommerce mail to my website. And everything works fine, the only problem is, it doesn't add to the bulk actions on the order site. Because we frequently resend emails for different purposes, this option would be very nice. Does anybody know how to add this?

Here's the code of the email class:

<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
 * A custom Expedited Order WooCommerce Email class
 *
 * @since 0.1
 * @extends \WC_Email
 */
class WC_Expedited_Order_Email extends WC_Email {
    /**
     * Set email defaults
     *
     * @since 0.1
     */
    public function __construct() {
        // set ID, this simply needs to be a unique name
        $this->id = 'wc_expedited_order';
        // this is the title in WooCommerce Email settings
        $this->title = 'Test Mail';
        // this is the description in WooCommerce email settings
    $this->customer_email   = true;
    // Kunde als Empfänger

        $this->description = 'Test Mail';
        // these are the default heading and subject lines that can be overridden using the settings
        $this->heading = 'Test Mail';
        $this->subject = 'Test Mail';
        // 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  = 'emails/customer-test.php';
        $this->template_plain = 'emails/plain/admin-new-order.php';

        //add_action( 'woocommerce_order_status_processing_to_completed_notification', array( $this, 'trigger' ) );
        //add_action( 'woocommerce_order_status_processing_to_testtragenbezahlt_notification',  array( $this, 'trigger' ) );
        // 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( $order_id ) {
        // bail if no order ID is present
        if ( ! $order_id )
            return;
        // setup order object
        $this->object = new WC_Order( $order_id );
    $this->recipient    = $this->object->billing_email;

        // replace variables in the subject/headings
        $this->find[] = '{order_date}';
        $this->replace[] = date_i18n( woocommerce_date_format(), strtotime( $this->object->order_date ) );
        $this->find[] = '{order_number}';
        $this->replace[] = $this->object->get_order_number();
        if ( ! $this->is_enabled() || ! $this->get_recipient() ) {
            return;
      }


        // woohoo, send the email!
        $this->send( $this->get_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() {
        ob_start();
        woocommerce_get_template( $this->template_html, array(
            'order'         => $this->object,
            'email_heading' => $this->get_heading()
        ) );
        return ob_get_clean();
    }
    /**
     * get_content_plain function.
     *
     * @since 0.1
     * @return string
     */
    public function get_content_plain() {
        ob_start();
        woocommerce_get_template( $this->template_plain, array(
            'order'         => $this->object,
            'email_heading' => $this->get_heading()
        ) );
        return ob_get_clean();
    }
    /**
     * Initialize Settings Form Fields
     *
     * @since 2.0
     */
    public function init_form_fields() {
        $this->form_fields = array(
            'enabled'    => array(
                'title'   => 'Enable/Disable',
                'type'    => 'checkbox',
                'label'   => 'Enable this email notification',
                'default' => 'yes'
            ),
            'subject'    => array(
                'title'       => 'Subject',
                'type'        => 'text',
                'description' => sprintf( 'This controls the email subject line. Leave blank to use the default subject: <code>%s</code>.', $this->subject ),
                'placeholder' => '',
                'default'     => ''
            ),
            'heading'    => array(
                'title'       => 'Email Heading',
                'type'        => 'text',
                'description' => sprintf( __( 'This controls the main heading contained within the email notification. Leave blank to use the default heading: <code>%s</code>.' ), $this->heading ),
                'placeholder' => '',
                'default'     => ''
            ),
            'email_type' => array(
                'title'       => 'Email type',
                'type'        => 'select',
                'description' => 'Choose which format of email to send.',
                'default'     => 'html',
                'class'       => 'email_type',
                'options'     => array(
                    'plain'     => __( 'Plain text', 'woocommerce' ),
                    'html'      => __( 'HTML', 'woocommerce' ),
                    'multipart' => __( 'Multipart', 'woocommerce' ),
                )
            )
        );
    }
} // end \WC_Expedited_Order_Email class

Thank you Lukas

  • 写回答

1条回答 默认 最新

  • douweng3564 2017-06-28 13:32
    关注

    yes there's actually a filter built in to WooCommerce to do this. Here's a small snippet that might help you.

    function change_order_action_resend_emails( $emails ) {
        $emails[] = 'wc_expedited_order'; 
        //Add all eMail ids you want to add
        return $emails;
    }
    
    add_filter( 'woocommerce_resend_order_emails_available', 'change_order_action_resend_emails' );

    </div>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看