Php 向特定电子邮件添加文本

Php 向特定电子邮件添加文本,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,我以前问过这个问题,但不幸的是,我意识到给出的答案不起作用,所以我再次问: 我试图添加一些文本到客户订单处理电子邮件从WooCommerce,它应该只添加在这个特定的电子邮件,只有当选择的付款方式是贝宝。我已经添加了文本,并且仅当选择Paypal作为付款方式时,文本才会显示在发送给客户的每封电子邮件中,例如,在订单完成电子邮件或客户备注电子邮件中。我有以下资料: add_action('woocommerce_email_before_order_table','add_order_email_

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

我试图添加一些文本到客户订单处理电子邮件从WooCommerce,它应该只添加在这个特定的电子邮件,只有当选择的付款方式是贝宝。我已经添加了文本,并且仅当选择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:';
        } 
}

我尝试了附加条件,比如$订单->的状态为“正在处理”,但没有工作。有什么帮助吗?

操作。。。我不知道为什么我认为你的邮件根本就没有发出

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

1难一点:禁用“客户订单处理”并创建自己的电子邮件模板。您可以从本教程开始:

2.更简单的建议:覆盖“customer order processing.php”,并在该模板中添加一些代码

以下是步骤:

进入WooCommerce->Settings->Email->Processing Order并单击“将文件复制到主题”。 如果它不存在,将在主题文件夹中创建一个“woocommerce”文件夹,您将在woocommerce->emails中找到模板文件 打开“customer processing order.php”,并在您喜欢的位置添加所需代码:

如果“贝宝”=$order->payment\u方法{ 回应“我的文字:”; }

代码没有经过测试,但应该可以工作


祝你好运

行动。。。我不知道为什么我认为你的邮件根本就没有发出

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

1难一点:禁用“客户订单处理”并创建自己的电子邮件模板。您可以从本教程开始:

2.更简单的建议:覆盖“customer order processing.php”,并在该模板中添加一些代码

以下是步骤:

进入WooCommerce->Settings->Email->Processing Order并单击“将文件复制到主题”。 如果它不存在,将在主题文件夹中创建一个“woocommerce”文件夹,您将在woocommerce->emails中找到模板文件 打开“customer processing order.php”,并在您喜欢的位置添加所需代码:

如果“贝宝”=$order->payment\u方法{ 回应“我的文字:”; }

代码没有经过测试,但应该可以工作


祝你好运

我相信我的补丁应该可以在WooCommerce 2.5上使用。如果是,那么$email对象将在woocommerce\u email\u before\u order\u表钩子和电子邮件中的其他钩子上可用,并且您将能够测试特定电子邮件的$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:';
    } 
}

我相信我的补丁应该在WooCommerce 2.5中提供。如果是,那么$email对象将在woocommerce\u email\u before\u order\u表钩子和电子邮件中的其他钩子上可用,并且您将能够测试特定电子邮件的$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:';
    } 
}

我只想在状态为“暂停”并发送给管理员而不是客户的电子邮件中添加一条注释。这对我来说很有效:

/* 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>';
    } 
}

我只想在状态为“暂停”并发送给管理员而不是客户的电子邮件中添加一条注释。这对我来说很有效:

/* 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>';
    } 
}

据我所知,没有一种方法可以告诉你在使用哪个电子邮件ID/类型。我觉得我以前看过这个,但在尝试修补WooCommerce时遇到了麻烦。我已经创建了一个可能在未来实现它的解决方案。如果不接受,您必须覆盖customer-order-processing.php模板。谢谢,我希望它能被接受!它被合并了,所以它在github的主分支中,但不确定它何时会正式发布。据我所知,当你使用它时,没有办法知道你使用的是哪种电子邮件ID/类型。我觉得我以前看过这个,但在尝试修补WooCommerce时遇到了麻烦。我已经创建了一个可能在未来实现它的解决方案。如果不接受,您必须覆盖customer-order-processing.php模板。谢谢,我希望它能被接受!它被合并了,所以它在github的主分支中,但不确定何时正式发布。更改优先级不会影响此电子邮件类型的条件。你说得对!我不知道为什么我认为电子邮件根本没有被触发!刚刚更新了我的答案。更改优先级不会影响此电子邮件类型的条件。你说得对!我不知道为什么我认为电子邮件根本没有被触发!刚刚更新了我的答案。太好了!你知道2.5什么时候发布吗?不知道。与此同时,@Francescocarucci的答案2应该可以用。我正在使用添加动作“woocommerce\u email\u before\u order\u table”,“添加订单\u email\u instruction”
ns',10,4;函数add_order_email_instructions$order、$sent_to_admin、$plain_text、$email{if'customer_processing_order'==$order->get_id&!$sent_to_admin{echo'您的登录详细信息正在发送途中。它们可能需要10分钟才能到达您的收件箱。;}在WooCommerce 3+中,$this->id不能飞行,$order->get\u id可以飞行。只有消息仍未与您的订单一起添加到块中。。已收到,正在处理中。想法?如果$email->id='customer\u processing\u order'。。。在最后工作很好!你知道2.5什么时候发布吗?不知道。同时,@Francescaralucci的答案2应该可以用。我正在使用添加动作“订单前添加商业邮件”,“添加订单邮件指示”,10,4;函数add_order_email_instructions$order、$sent_to_admin、$plain_text、$email{if'customer_processing_order'==$order->get_id&!$sent_to_admin{echo'您的登录详细信息正在发送途中。它们可能需要10分钟才能到达您的收件箱。;}在WooCommerce 3+中,$this->id不能飞行,$order->get\u id可以飞行。只有消息仍未与您的订单一起添加到块中。。已收到,正在处理中。想法?如果$email->id='customer\u processing\u order'。。。终于成功了