首页 文章

定位WooCommerce客户处理和完成的订单电子邮件通知

提问于
浏览
1

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

只有在客户选择“Local Pickup”作为送货方式时才应添加 .

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订单管理页面手动发送的“订单详细信息/发票”电子邮件中 .

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

2 回答

  • 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

  • 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>';
    }
    

相关问题