【问题标题】:woocommerce add text to specific emailwoocommerce 将文本添加到特定电子邮件
【发布时间】:2016-02-01 01:37:46
【问题描述】:

我之前问过这个问题,但不幸的是我意识到给出的答案不起作用,所以我再次问:

I am trying to add some text to the customer-order-processing email from WooCommerce, and it should ONLY be added in this particular email and ONLY if chosen payment method is Paypal.我已经到目前为止,只有添加文本,只有在PayPal被选为付款方式时,只有在付款方式中,文本将在每封电子邮件中显示到客户端,例如订单完成的电子邮件或客户 - 笔记电子邮件。我有以下内容:

add_action('woocommerce_email_before_order_table','add_order_email_instructions', 0, 2);
            function add_order_email_instructions( $order, $sent_to_admin ) {
        if ( 'paypal' == $order->payment_method && ! $sent_to_admin ) {
            echo 'my text:';
        } 
}

我尝试过使用其他条件,例如 ! $order->has_status( 'processing' ),但没有任何效果。有什么帮助吗?

【问题讨论】:

  • 据我所知,没有办法知道您在使用哪个电子邮件 ID/类型。我觉得我以前看过这个,但是在尝试修补 WooCommerce 时遇到了麻烦。
  • 我创建了一个pull request,将来可能会实现。如果不接受它们,则必须覆盖 customer-order-processing.php 模板。
  • 谢谢,希望能被采纳!
  • 被合并了,所以在github的master分支里,但不知道什么时候正式发布。

标签: php wordpress woocommerce


【解决方案1】:

操作...我不知道为什么我认为您的电子邮件根本没有触发。

顺便说一句,如果您只想将该文本添加到特定的电子邮件模板,有两种方法:

  1. 更难的一个:禁用“客户订单处理”并创建您自己的电子邮件模板。你可以从这个教程开始:https://www.skyverge.com/blog/how-to-add-a-custom-woocommerce-email/

  2. 更简单且推荐:覆盖“customer-order-processing.php”并在该模板中添加一些代码。

步骤如下:

  • 进入 WooCommerce -> 设置 -> 电子邮件 -> 处理订单,然后单击“将文件复制到主题”。

  • 如果它不存在,将在您的主题文件夹中创建一个“woocommerce”文件夹,您将在 woocommerce -> 电子邮件中找到模板文件

  • 打开“customer-processing-order.php”并在您喜欢的地方添加所需的代码:

    if( 'paypal' == $order->payment_method ) {
     echo 'my text:';
    }
    

代码未经测试,但应该可以工作!

祝你好运;)

【讨论】:

  • 更改优先级不会影响这是哪种电子邮件类型的条件。
  • 你说得对!我不知道为什么我认为电子邮件根本没有触发!刚刚更新了我的答案。
【解决方案2】:

我相信我的补丁应该可以与 WooCommerce 2.5 一起使用。如果是,那么$email 对象将在woocommerce_email_before_order_table 挂钩(以及电子邮件中的其他挂钩)上可用,您将能够测试$email->id 的特定电子邮件。您的functions.php(或最好在插件中)中的以下内容应该这样做:

add_action( 'woocommerce_email_before_order_table','add_order_email_instructions', 10, 4 );
function add_order_email_instructions( $order, $sent_to_admin, $plain_text, $email ) {
    if ( 'customer_processing_order' == $this->id && 'paypal' == $order->payment_method && ! $sent_to_admin ) {
        echo 'my text:';
    } 
}

【讨论】:

  • 太棒了!你知道2.5什么时候发布吗?
  • 不,我不知道。与此同时,@FrancescoCarlucci 的答案 #2 应该有效。
  • 我现在在 WooCommerce 3+ 中使用add_action( 'woocommerce_email_before_order_table','add_order_email_instructions', 10, 4 ); function add_order_email_instructions( $order, $sent_to_admin, $plain_text, $email ) { if ( 'customer_processing_order' == $order->get_id() && ! $sent_to_admin ) { echo 'Your login details are on their way. (They may take up to 10 minutes to arrive in your inbox.'; } },因为 $this->id 不会飞,而 $order->get_id() 会。只有消息仍未添加到带有“您的订单..已收到并正在处理中。”的块中。想法?
  • if ( $email->id == 'customer_processing_order' )... 终于成功了
【解决方案3】:

我只想在状态为“保留”并发送给管理员(而非客户)的电子邮件中添加注释。这对我很有效:

/* Add manual processing note to new orders to admin */
add_action( 'woocommerce_email_order_details','add_order_email_instructions', 10, 4 );
function add_order_email_instructions( $order, $sent_to_admin, $plain_text, $email ) {
    if ( $order->status == 'on-hold' && $sent_to_admin ) {
        echo '<p><strong>Note: Manual processing for this order is required.</strong></p>';
    } 
}

【讨论】:

    猜你喜欢
    • 2018-09-19
    • 2021-12-11
    • 2018-05-22
    • 2018-09-21
    • 1970-01-01
    • 1970-01-01
    • 2015-10-08
    • 2019-04-08
    • 2016-08-02
    相关资源
    最近更新 更多