php - Woocommerce 自定义电子邮件
问题描述
我需要有关 woocommerce 的自定义电子邮件挂钩的帮助。
每当产品完成时,我都会尝试根据产品 ID 发送不同的电子邮件。
我的代码不起作用,如下所示:
/**************
DIFFERENT MESSAGES FOR DIFFERENT PRODUCTS
****************/
//hook our function to the new order email
add_action('woocommerce_email_order_details', 'uiwc_email_order_details_products', 1, 4);
function uiwc_email_order_details_products($order, $admin, $plain, $email) {
$status = $order->get_status();
// checking if it's the order status we want
if ( $status == "completed" ) {
$items = $order->get_items();
if ( $item['product_id'] == "3181") {
echo __( '<strong>IMPORTANT - NEXT STEP:</strong><br>To get started, please follow <a href="https:XXXXX">this link</a> to complete the Policies form.<br><br>This is a really important first step, and only takes about 5 minutes. After completeing the Policies form, you will receive additional instructions on next steps.<br><br>Congratulations! Let your journey begin.<br><br>', 'uiwc' );
}
elseif ( $item['product_id'] == "3223") {
echo __( '<strong>IMPORTANT - NEXT STEP:</strong><br>Differnet product so differenct email....<br><br>', 'uiwc' );
}
}
}
非常感谢任何建议
解决方案
您的代码中存在一些错误,请尝试以下操作
//hook our function to the new order email
add_action( 'woocommerce_email_order_details', 'custom_email_order_details', 4, 4 );
function custom_email_order_details( $order, $admin, $plain, $email ) {
$domain = 'woocommerce';
// checking if it's the order status we want
if ( $order->has_status('completed') ) {
foreach( $order->get_items() as $item ){
if ( $item->get_product_id() == '3181' ) {
echo __( '<strong>IMPORTANT - NEXT STEP:</strong><br>To get started, please follow <a href="https://xxxxxx">this link</a> to complete the Policies form.<br><br>This is a really important first step, and only takes about 5 minutes. After completeing the Policies form, you will receive additional instructions on next steps.<br><br>Congratulations! Let your journey begin.<br><br>', $domain );
break;
}
elseif ( $item->get_product_id() == '3223' ) {
echo __( '<strong>IMPORTANT - NEXT STEP:</strong><br>Differnet product so differenct email....<br><br>', $domain );
break;
}
}
}
}
代码位于您的活动子主题(或活动主题)的 function.php 文件中。测试和工作。
推荐阅读
- javascript - 当有人使用 javascript 或 jquery 粘贴文本时,如何仅在输入字段内的文本开头禁用/删除空格?
- python - 如何在python中加载多个json对象
- javascript - Javascript 承诺无法捕获超时或 500 服务器错误
- javascript - 多个套接字客户端
- c# - 应用程序不会从笔记本电脑部署
- python - 如何确定已安装 conda 包的确切软件版本?
- python-3.x - Python 请求 utf-8 后响应得到一个 ascii 解码错误
- kotlin - 如何为 boolean.class/Boolean::class.javaPrimitiveType 和 Boolean.class/Boolean.class.java 注册类型适配器
- java - Log4j java 版本在每行堆栈跟踪的末尾
- android - Android Studio:连接超时:连接