woocommerce将文本添加到特定电子邮件

时间:2015-10-31 20:15:27

标签: php wordpress woocommerce

之前我曾经问过这个,但不幸的是我意识到答案没有用,所以我再问:

我正在尝试将一些文字添加到$('#certButton').delay(500).animate({ 'opacity': [ 1, "linear" ]}, { duration:500, complete: function() { document.getElementById("certButton").style.pointerEvents = "visible"; } }); 的客户订单处理电子邮件中,并且只应在此特定电子邮件中添加,并且仅在选择的付款方式为WooCommerce时才会添加。我已经添加了文本,只有当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:'; } } ,但没有任何效果。有什么帮助吗?

3 个答案:

答案 0 :(得分:2)

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

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

答案 1 :(得分:1)

行动......我不知道为什么我认为你的电子邮件根本没有解雇。

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

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

2)更容易和推荐:覆盖&#39; customer-order-processing.php&#39;并在该模板中添加一些代码。

这是步骤:

  • 进入WooCommerce - &gt;设置 - &gt;电子邮件 - &gt;处理订单并点击“将文件复制到主题&#39;。
  • 如果它不存在,那么&#39; woocommerce&#39;文件夹将在您的主题文件夹中创建,您将在woocommerce中找到模板文件 - &gt;电子邮件
  • open&#39; customer-processing-order.php&#39;并在您喜欢的地方添加所需的代码:

    if(&#39; paypal&#39; == $ order-&gt; payment_method){     回声我的文字:&#39 ;; }

代码未经过测试但应该有效!

祝你好运;)

答案 2 :(得分:1)

我相信我的补丁应该可以通过 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:';
    } 
}