【问题标题】:Targetting WooCommerce customer processing and completed order email notifications针对 WooCommerce 客户处理和完成的订单电子邮件通知
【发布时间】:2018-05-31 13:14:51
【问题描述】:

我正在尝试在 Woocommerce 上的订单表之后添加自定义内容 “处理订单”和“订单已完成”客户电子邮件,使用以下代码。

仅当客户选择“本地取货”作为送货方式时才应添加。

function local_pickup_extra_content_email($order, $is_admin_email) {
    if ( $is_admin_email ) {
        return;
    }

    if ( ICL_LANGUAGE_CODE == "he" && strpos( $order->get_shipping_method(), 'Local Pickup' ) !== false) {
        echo '<p><strong>Note:</strong> Please wait for telephone confirmation of local pickup.</p>';
    }
}

add_action( 'woocommerce_email_after_order_table', 'local_pickup_extra_content_email', 10, 2  );

内容未添加到指定的电子邮件中。它仅被添加到通过 Woocommerce 订单管理页面手动发送的“订单详情/发票”电子邮件中。

如何将上述内容添加到提到的电子邮件中?我究竟做错了什么?
(主题文件夹中的电子邮件模板不会被覆盖)

【问题讨论】:

    标签: php wordpress woocommerce orders email-notifications


    【解决方案1】:

    这可以通过缺少的钩子参数$email轻松定位那些电子邮件通知,这样:

    add_action( 'woocommerce_email_after_order_table', 'local_pickup_extra_content_email', 10, 4  );
    function local_pickup_extra_content_email( $order, $sent_to_admin, $plain_text, $email ) {
        // Only for "Processing Order" and "Order Completed" customer emails
        if( ! ( 'customer_processing_order' == $email->id || 'customer_completed_order' == $email->id ) ) return;
    
        $lang = get_post_meta( $order->id, 'wpml_language', true );
        if ( $lang == 'he' && && strpos( $order->get_shipping_method(), 'Local Pickup' ) !== false) {
            echo '<p><strong>Note:</strong> Please wait for telephone confirmation of local pickup.</p>';
        }
    }
    

    此代码在您的活动子主题(或主题)的 function.php 文件中或任何插件文件中。

    经过测试并且可以工作


    类似答案:Add a custom text to specific email notification for local pickup Woocommerce orders

    【讨论】:

    • 感谢您的回答。由于我的 WPML 条件,这不起作用:ICL_LANGUAGE_CODE == "he" 我猜ICL_LANGUAGE_CODE 在发送 Woocommerce 电子邮件时不存在。为了解决这个问题,我用以下代码替换了上面的行,它就像一个魅力:$lang = get_post_meta( $order-&gt;id, 'wpml_language', true );if ( $lang == 'he' &amp;&amp; ...) {
    • 带我去谷歌搜索并找到处理订单 ID 挂钩,谢谢。
    【解决方案2】:

    由于 if 语句中的 WPML 条件,这不起作用:

    ICL_LANGUAGE_CODE == "he" 
    

    我认为 Woocommerce 发送电子邮件时不存在 ICL_LANGUAGE_CODE。为了解决这个问题,我用以下内容替换了上面问题中的 if 语句,它就像一个魅力:

    $lang = get_post_meta( $order->id, 'wpml_language', true );
    if ( $lang == 'he' && && strpos( $order->get_shipping_method(), 'Local Pickup' ) !== false) {
        echo '<p><strong>Note:</strong> Please wait for telephone confirmation of local pickup.</p>';
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-19
      • 1970-01-01
      • 2021-06-23
      • 2019-12-05
      • 2018-06-07
      • 2014-03-09
      • 2021-04-02
      • 2017-05-19
      相关资源
      最近更新 更多