针对 WooCommerce 客户处理和完成的订单电子邮件通知
Targetting WooCommerce customer processing and completed order email notifications
我正在尝试在 Woocommerce 上的订单 table 之后添加自定义内容
"Processing Order" 和 "Order Completed" 客户电子邮件,使用以下代码。
仅当客户选择 "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 订单管理页面手动发送的 "Order Details/Invoice" 电子邮件中。
如何将以上内容添加到提到的电子邮件中?我究竟做错了什么?
(主题文件夹中的电子邮件模板未被覆盖)
这可以通过缺少的钩子参数 $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 文件或任何插件文件中。
已测试并有效
相似答案:
由于我在 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>';
}
我正在尝试在 Woocommerce 上的订单 table 之后添加自定义内容 "Processing Order" 和 "Order Completed" 客户电子邮件,使用以下代码。
仅当客户选择 "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 订单管理页面手动发送的 "Order Details/Invoice" 电子邮件中。
如何将以上内容添加到提到的电子邮件中?我究竟做错了什么?
(主题文件夹中的电子邮件模板未被覆盖)
这可以通过缺少的钩子参数 $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 文件或任何插件文件中。
已测试并有效
相似答案:
由于我在 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>';
}