Php 当订单为订阅父项时,WooCommerce不应发送订单完整邮件
当客户购买订阅时,我尝试取消发送WooCommerce默认订单完整邮件。WooCommerce为该订阅创建父订单。当我们关闭父订单时,客户将通过邮件收到已完成的订单。然后,我们尝试不阻塞,只对订阅的父订单进行阻塞 我找到了,但它是用来更新已完成的邮件的 有一个infoPhp 当订单为订阅父项时,WooCommerce不应发送订单完整邮件,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,当客户购买订阅时,我尝试取消发送WooCommerce默认订单完整邮件。WooCommerce为该订阅创建父订单。当我们关闭父订单时,客户将通过邮件收到已完成的订单。然后,我们尝试不阻塞,只对订阅的父订单进行阻塞 我找到了,但它是用来更新已完成的邮件的 有一个infoorder\u type应该存储信息,如果它是订阅父订单或不是订阅父订单,如何访问该值 如果是父订阅订单,也可以通过wcs\u order\u contains\u subscription()进行检查。() 类似这样:wcs\u订
order\u type
应该存储信息,如果它是订阅父订单或不是订阅父订单,如何访问该值
如果是父订阅订单,也可以通过wcs\u order\u contains\u subscription()
进行检查。()
类似这样:wcs\u订单\u包含订阅($order,$order\u type)
更新:
根据新信息,这是当前状态:
// Conditionally remove action to send order completed email for subscription parent order
function unhook_order_complete_email_subscription_parent($email_class) {
// Check whether to send the parent order completed email or not
$send_parent_completed_email = order_type(parent);
if (!$send_parent_completed_email) {
// Remove action to prevent email from being sent
remove_action(
"woocommerce_order_status_completed_notification",
array(
$email_class->emails["WC_Email_Customer_Completed_Order"],
"trigger"
)
);
}
}
add_action("woocommerce_order_status_changed", "unhook_order_complete_email_subscription_parent");
没有类似于
order\u type()
的函数。这将解决您的问题:
// Conditionally remove action to send order completed email for subscription parent order
function unhook_order_complete_email_subscription_parent($order_id) {
$email_class = wc()->mailer()->get_emails();
// Check whether to send the parent order completed email or not
$order = wc_get_order($order_id);
if ($order && !$order->get_parent_id()) {
// Remove action to prevent email from being sent
remove_action(
"woocommerce_order_status_completed_notification",
array(
$email_class->emails["WC_Email_Customer_Completed_Order"],
"trigger"
)
);
}
}
add_action("woocommerce_order_status_changed", "unhook_order_complete_email_subscription_parent");
编辑:
这是一个更好的方法<如果订单是父订单,则code>get\u parent\u id()将返回0,否则如果订单是子订单,则返回parent\u id
function enable_email($order) {
// We have to restore the configuration of what we disabled after we are done with our hack
if ($order->get_parent_id() != 0 && ($status = get_transient( "tmp_completed_order_email" )) !== false) {
wc()->mailer()->emails['WC_Email_Customer_Completed_Order']->enabled = $status;
}
}
function disable_email($order)
{
if ($order->get_parent_id() != 0) { // It is a child
// Store the current configuration in a temporary place.
$current_status = wc()->mailer()->emails['WC_Email_Customer_Completed_Order']->enabled;
// Everything should be done in 10 seconds. Lets keep the data till then
set_transient( 'tmp_completed_order_email', $current_status, 10 );
// Disabled completed order email
wc()->mailer()->emails['WC_Email_Customer_Completed_Order']->enabled = 'no';
}
}
add_action("woocommerce_before_order_object_save", "disable_email");
add_action("woocommerce_after_order_object_save", "enable_email");
当订单详细信息丢失时,可能您正在挂接一个更晚的函数。挂接到订单状态更改?删除此钩子中的操作,这样您的意思是当前代码是正确的,但只是一个函数太晚了?是的,您正在查看订单详细信息,以便验证它是否是的父级
woocommerce\u email
不会传递订单数据,其业务woocommerce\u order\u status\u changed
将传递order\u id
作为其第一个参数。因此,是的,挂接到woocommerce\u order\u status\u changed
,然后在该方法中运行remove\u操作。见更新的问题。我认为我们走的是对的…没有按我们想要的那样工作。对于父订阅订单,还将发送订单完整邮件。这可能是一个钩子优先级问题吗?你也使用了订阅吗?因为这个代码在我的系统上不起作用。我想知道这对你方是否有效对不起,我不在。是的,它只发送给家长。它也发送给孩子吗?我用更新的方法进行了编辑如果您不想发送给家长,请更改=代码>到==
。Aget\u parent\u id()==0
表示它是父对象