Woocommerce-发送通知电子邮件到自定义状态顺序

时间:2018-09-24 22:25:38

标签: woocommerce hook-woocommerce woocommerce-subscriptions woocommerce-bookings woocommerce-theming

我需要为woocommerce创建自定义订单,并将通知发送给客户。

但是当我创建这些订单时,它们会显示在订单页面上,但是当它们被激活时,它们不会发送电子邮件通知客户。

例如:

我创建了名为 wc-发票

的自定义订单“ Nota Fiscal”
    function register_invoice_order_status() {
    register_post_status( 'wc-invoice', array(
        'label'                     => 'Nota Fiscal',
        'public'                    => true,
        'exclude_from_search'       => false,
        'show_in_admin_all_list'    => true,
        'show_in_admin_status_list' => true,
        'label_count'               => _n_noop( 'Nota Fiscal <span class="count">(%s)</span>', 'Nota Fiscal <span class="count">(%s)</span>' )
    ) );
}
add_action( 'init', 'register_invoice_order_status' );

// Add to list of WC Order statuses
function add_invoice_to_order_statuses( $order_statuses ) {
    $new_order_statuses = array();
    foreach ( $order_statuses as $key => $status ) {
        $new_order_statuses[ $key ] = $status;
        if ( 'wc-processing' === $key ) {
            $new_order_statuses['wc-invoice'] = 'Nota Fiscal';
        }
    }
    return $new_order_statuses;
}
add_filter( 'wc_order_statuses', 'add_invoice_to_order_statuses' );

// As of WooCommerce 2.3
function so_27112461_woocommerce_email_actions( $actions ){
    $actions[] = 'woocommerce_order_status_wc-invoice';
    return $actions;
}
add_filter( 'woocommerce_email_actions', 'so_27112461_woocommerce_email_actions' );

我为WC_Email创建了一个类

class WC_Email_Invoice_Order extends WC_Email { 
public function __construct() {

        // set ID, this simply needs to be a unique name
        $this->id = 'wc_invoice';

        // this is the title in WooCommerce Email settings
        $this->title = 'Nota Fiscal';

        // this is the description in WooCommerce email settings
        $this->description = 'Confirmando envio de Nota Fiscal';

        // these are the default heading and subject lines that can be overridden using the settings
        $this->heading = ' Nota Fiscal';
        $this->subject = ' Nota Fiscal';

        // 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-confirmed-order.php';
        $this->template_plain = 'emails/plain/admin-new-order.php';

        // Trigger on confirmed orders
        add_action( 'woocommerce_order_status_pending_to_wc_invoice', array( $this, 'trigger' ) );
        add_action( 'woocommerce_order_status_processing_to_wc_invoice', array( $this, 'trigger' ) );

        // Call parent constructor to load any other defaults not explicity defined here
        parent::__construct();

        // this sets the recipient to the settings defined below in init_form_fields()
        $this->recipient = $this->get_option( 'recipient' );

        // if none was entered, just use the WP admin email as a fallback
        if ( ! $this->recipient )
            $this->recipient = get_option( 'admin_email' );
    }

将状态更改为“发票”时,它不会将通知发送到电子邮件。 change order for Nota Fiscal

会发生什么?

0 个答案:

没有答案