[英]WooCommerce should NOT send order complete mail when order is subscription parent
当客户购买订阅时,我尝试取消发送 WooCommerce 默认订单完成邮件。 WooCommerce 为该订阅创建父订单。 当我们关闭该父订单时,客户将收到订单完成邮件。 然后我们尝试不阻止,但仅针对订阅的父订单。
我找到了这个答案,但它用于更新已完成的邮件。
有一个 info order_type
应该存储信息,如果它是订阅父订单或不是,如何访问该值?
如果它是父订阅订单,也许还有一种方法可以通过wcs_order_contains_subscription()
检查。 ( https://docs.woocommerce.com/document/subscriptions/develop/functions/order-cart-functions/ )
像这样的东西: wcs_order_contains_subscription( $order, $order_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_type()
这样的 function 。 这应该可以解决您的问题:
// 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");
编辑:
这是一种更好的方法。 如果订单是父订单, get_parent_id()
将返回 0,否则如果订单是子订单,它将返回parent_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");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.