php - 发送有关订单状态从自定义更改为处理的处理电子邮件通知
问题描述
我只是在 WooCommerce插件的自定义订单状态的帮助下为我的订单创建了一个自定义状态“树”(“在树中等待”-已标记) 。当用户成功完成支付后,状态会从“pending”变为“tree”。经过一些处理后,我会将状态更改为正在处理,此时我需要将处理邮件发送给用户。我该怎么做,我只是找到上面的代码来注册电子邮件。
function so_27112461_woocommerce_email_actions( $actions ){
$actions[] = 'woocommerce_order_status_tree_to_processing';
return $actions;
}
add_filter( 'woocommerce_email_actions', 'so_27112461_woocommerce_email_actions' );
但是我怎样才能触发处理邮件。
解决方案
您使用的插件有点过时(自 WooCommerce 3 版本以来未更新)。
你不需要任何插件来做你想做的事,只需要下面的几个钩子函数:
// Add custom status to order list
add_action( 'init', 'register_custom_post_status', 10 );
function register_custom_post_status() {
register_post_status( 'wc-tree', array(
'label' => _x( 'Waiting in tree', 'Order status', 'woocommerce' ),
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Waiting in tree <span class="count">(%s)</span>', 'Waiting in tree <span class="count">(%s)</span>', 'woocommerce' )
) );
}
// Add custom status to order page drop down
add_filter( 'wc_order_statuses', 'custom_wc_order_statuses' );
function custom_wc_order_statuses( $order_statuses ) {
$order_statuses['wc-tree'] = _x( 'Waiting in tree', 'Order status', 'woocommerce' );
return $order_statuses;
}
// Adding custom status 'tree' to admin order list bulk dropdown
add_filter( 'bulk_actions-edit-shop_order', 'custom_dropdown_bulk_actions_shop_order', 20, 1 );
function custom_dropdown_bulk_actions_shop_order( $actions ) {
$actions['mark_tree'] = __( 'Mark Waiting in tree', 'woocommerce' );
return $actions;
}
// Enable the action
add_filter( 'woocommerce_email_actions', 'filter_woocommerce_email_actions' );
function filter_woocommerce_email_actions( $actions ){
$actions[] = 'woocommerce_order_status_wc-tree';
return $actions;
}
// Send Customer Processing Order email notification when order status get changed from "tree" to "processing"
add_action('woocommerce_order_status_changed', 'custom_status_email_notifications', 20, 4 );
function custom_status_email_notifications( $order_id, $old_status, $new_status, $order ){
if ( $old_status == 'tree' && $new_status == 'processing' ) {
// Get all WC_Email instance objects
$wc_emails = WC()->mailer()->get_emails();
// Sending Customer Processing Order email notification
$wc_emails['WC_Email_Customer_Processing_Order']->trigger( $order_id );
}
}
代码位于您的活动子主题(或活动主题)的 function.php 文件中。测试和工作。
推荐阅读
- html - 当有人输入他们的电子邮件并订阅时,如何在 html 中设置“您已订阅”通知?
- python - 你能得到多个正确的回报ELIF吗?
- javascript - JS如何在循环中多次打开新标签
- python - 无法从 Django 中的 mysite.views 导入函数
- r - 你如何在 R 中找到柱形图的统计数据?
- flutter - 更新复杂树中的特定小部件
- java - 为什么 Spring Boot 会生成一个无法为其单元测试加载上下文的项目?
- c# - OWIN 存储更新、插入或删除语句影响了意外的行数 (0) 错误
- javascript - TypeError:props.set 不是函数
- java - 更改语言环境不会影响字体类型