当前位置: 首页 > 知识库问答 >
问题:

添加自定义电子邮件Woocommerce

宰父熙云
2023-03-14

我有一个插件管理我的货件与两个自定义状态:等待-装运和装运。

我尝试添加一个电子邮件发送时,订单传递到发货。

我在Stack Overflow:Woocommerce退款电子邮件中发现了这一点,但我可以知道它是如何工作的

下面是我的插件文件代码:
我用下面的helgatheviking和Adrien Leber的建议更新了我的代码

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 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个答案

沈琛
2023-03-14

我想你误解了这一部分:

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;

}

希望有帮助。

 类似资料:
  • WordPress-WooCommerce 我想做的是: null 邮件里什么也没印。 请解决。提前谢了。

  • 我使用laravel 5.6,并成功地将视图作为电子邮件发送。 我使用以下代码: 我唯一的问题是密码重置。我知道我可以自定义一点模板,但是如何覆盖默认的电子邮件模板并发送我自己的视图? 我尝试写我自己的ResetPassword通知: 但我只能翻译电子邮件。我想要的是根据我自己的模板发送我自己的视图。 可能吗? 谢谢你的帮助。

  • 有什么方法我可以添加内容从一个自定义产品字段到‘订单完成'WooCommerce电子邮件? 我已经将此代码添加到functions.php中,以便将自定义字段保存到产品元信息中。 上面的代码工作得很好,它显示了所有“订单完成”电子邮件的自定义文本。 但是,我想用自定义产品字段数据替换文本的URL部分。每个产品的数据都不同。 谢了。

  • 我试图发送电子邮件使用Nodejs包Nodemailer,但我无法更改从电子邮件到我的自定义域电子邮件。任何帮助都将不胜感激。这是我用来发送电子邮件的代码。

  • 我希望管理电子邮件的电子邮件主题行根据产品类别进行更改。我看过所有类似的堆栈溢出问题,但没有一个适用于Woocommerce3.8.0(参见这个和这个)。 我有的是这个 我的代码只是返回新订单的默认电子邮件主题行(在woocommerce/settings/email中设置)。我想不通为什么我的函数不能识别类别名称。 谁能告诉我我的代码出了什么问题吗? 我将这段代码放在我的child-theme/