首页 文章

添加自定义电子邮件Woocommerce

提问于
浏览
0

我有一个用于管理我的货物的插件有两个自定义状态:等待装运和装运 .

我尝试添加订单传递到发货时发送的电子邮件 .

我在Stack Overflow上找到了这个:Woocommerce Refund Email但我可以看出它是如何工作的

这是我的插件文件代码:
I updated my code with the recommendations of helgatheviking and Adrien Leber below

function shippement_tracking_filter_actions( $actions ){
    $actions[] = "woocommerce_order_status_shipped";
    return $actions;
}
add_filter( 'woocommerce_email_actions', 'shippement_tracking_filter_actions' );

function add_expedited_order_woocommerce_email( $email_classes ) {
    require( 'includes/class-wc-expedited-order-email.php' );
    $email_classes['WC_Expedited_Order_Email'] = new WC_Expedited_Order_Email();
    return $email_classes;
}
add_filter( 'woocommerce_email_classes', 'add_expedited_order_woocommerce_email' );`

而我的 class :

class WC_Expedited_Order_Email extends WC_Email {
    public function __construct() {

        $this->id               = 'expedited_order_tracking';
        $this->customer_email   = true;
        $this->title            = __( 'Shippement Traking', 'customEmail' );
        $this->description      = __( 'Sent tracking email to customer', 'customEmail' );
        $this->heading          = __( 'Your {site_title} order is shipped', 'customEmail' );
        $this->subject          = __( 'Your {site_title} order from {order_date} is shipped', 'customEmail' );

        $this->template_html    = 'emails/customer-order_tracking.php';
        $this->template_plain   = 'emails/plain/customer-order_tracking.php';

        add_action( 'woocommerce_order_status_shipped', array( $this, 'trigger' ) );

        parent::__construct();
    }

    public function trigger( $order_id )
    {
        var_dump($order_id);die();
    }

当我改变订单状态时,没有任何反应!我的触发功能永远不会调用 .

谁能帮我?

1 回答

  • 0

    我想你误解了这一部分:

    function add_expedited_order_woocommerce_email( $email_classes ) {
       $email_classes['WC_Expedited_Order_Email'] = include( plugin_dir_path( __FILE__ ) . '/class-wc-expedited-order-email.php' );
       return $email_classes;
    }
    

    您必须先包含类文件,然后创建此类的新实例:

    function add_expedited_order_woocommerce_email( $email_classes ) {
    
        // include our custom email class
        require( 'includes/class-wc-expedited-order-email.php' );
    
        // add the email class to the list of email classes that WooCommerce loads
        $email_classes['WC_Expedited_Order_Email'] = new WC_Expedited_Order_Email();
    
        return $email_classes;
    
    }
    

    希望能帮助到你 .

相关问题